Difference between code beside and code behind

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

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

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

Method 2

This article explains that code beside using the partial class pattern was introduced in ASP.Net 2.0 to replace the code behind model used for .Net 1.0 – but as everyone still calls the separated code – .aspx.cs or .aspx.vb – code behind there is no practical difference now.

In asp.net 1.0 development you had to declare every control used in the aspx page in the code behind; and for some reason this was flaky and the event wiring kept being deleted after a solution was compiled. So perhaps the initial rename was because the code behind model was unstable in .net 1.0.


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x