Difference between code beside and code behind
Can a开发者_开发技巧nyone tell me what are the differences between code beside and code behind in Asp.NET?
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
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.
精彩评论