Udostępnij za pośrednictwem


The complete picture of ASP.NET 2.0 compilation

ASP.NET 2.0 compilation is much different than ASP.NET 1.x compilation.

In ASP.NET 1.x there was two classes for each web form:

1) Code-behind class ---> which is compiled inside the assembly in the bin folder along with all other classes for all web forms

2) Run time-generated class ---> which is generated at run time from the aspx markup code and inherits the code-behind file

Maintaining the Inheritance relation between the two files and the fact that the all code behind classes compiled in one assembly produced two major defects to ASP.NET

1) All the web forms should be programmed using one programming language (VB.NET, C#, J#) which restrains the teams that have VB and C# developers.

2) There’s much code injected in the code-behind class to keep a declaration in the code behind page synchronized with the markup in the aspx page.

But in ASP.NET 2.0 the whole model changed. Thanks to the new .NET framework partial keyword, we can now create a class that spans more than one file. The model is as following

1) Both code-behind class and the aspx markup are compound in one class (you will notice that the code-behind class has the keyword partial)

2) Any inline code (if there’s any) will be added to another class which inherits the above class (very important, it’s neglected in most articles that deals with this issue) So you can’t declare a private member in the code-behind class and consume it in the inline code in the aspx page.

This model can be illustrated using this figure

This model generates a simpler cod-behind file because there’s no need for all declaration and initialization code provided in the ASP.NET 1.x compilation model.

The file that is generated from the code-behind and the aspx markup not necessary to be compiled with all other auto-generated classes. ASP.NET compiles the files of the same language together. Which enable creating web sites with more than one language.

Special thanks to Simon Calvert and Dmitry Robsman from Microsoft for their help in this issue.

Have fun,

Mohamed