Can anyone tell me what are the differences between code beside and code behind in Asp.NET?
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.
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.
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.
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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With