Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between code beside and code behind

Tags:

c#

asp.net

Can anyone tell me what are the differences between code beside and code behind in Asp.NET?

like image 252
pikk Avatar asked May 07 '11 22:05

pikk


People also ask

What is the code behind?

Code-behind is a technique used in Microsoft programming platforms, including ASP.NET and XAML, where the practice is facilitated by separating the visual and code aspects through the use of partial classes.

What is the difference between inline code and code behind?

One major point of Code-Behind is that the code for all the Web pages is compiled into a DLL file that allows the web pages to be hosted free from any Inline Server Code. Inline Code refers to the code that is written inside an ASP.NET Web Page that has an extension of . aspx.

What is mean by code behind class?

Code-behind refers to code for your ASP.NET page that is contained within a separate class file. This allows a clean separation of your HTML from your presentation logic.

What is the main feature of code behind?

The code-behind feature of ASP.NET enables you to divide an ASP.NET page into two files - one consisting of the presentation data, and the second, which is also called the code-behind file, consisting of all the business logic.


1 Answers

CodeInPage: which means putting our code into our page.

CodeBehind is a separate file for the code. This file derives from Page, contains declarations for the server controls, and contains all the event handlers and such. The aspx file then derives from this class for the final page.
The two problems that CodeBehind solves is that intellisense needed 1 language per file to work, so the serverside code was put in one file and we are happy. It also eases the compiler pain of detecting bugs in serverside code, as it only needs to deal with the code files by themselves, not the ui declaration mixed in.

Code-Beside allows one class to be defined in multiple source files.
The main intended use for Partial Types is to allow code generators to create a class that can be extended in a separate file to not mess up any re-generation.


Refer to the following article:

ASP.NET v2.0: Code-Beside Replaces Code-Behind

like image 115
Akram Shahda Avatar answered Oct 05 '22 02:10

Akram Shahda