Changes in page compilation model in ASP. NET 2.0 Beta2

Source: Internet
Author: User

First, return to the "Ancient Times" of ASP. NET 1.1 to see how the ASP. NET engine processes page files and Code-Behind files.

We usually see the following statement above the page file:

<% @ Page CodeBehind = "Default. aspx. cs" Inherits = "WebApplication1.CDefault" %>

When we add a new ASP.. NET Control,. NET will automatically add a protecte object declaration in the Code-Behind Code file, and use and operate this object in the Code. VS. NET always maintains the synchronization between the controls in the page file and the control object declarations in the code file.

When we compile the site, VS. NET compiles all Code-Behind files together to generate a. dll file in the/bin directory. Then, we deploy all the page files and/bin on the server. ASP. the NET engine automatically generates. cs class file, and according to the content specified by "Inherits" in the header Declaration of the page file, let this class inherit from the specified parent class. In this way, the page is combined with the content in the background code file by "inheritance.

The biggest problem with this page compilation model is that the controls in the page must be synchronized with the control object declaration in Code-Behind at all times. Although developers do not realize this, if. if the synchronization fails due to an error in NET, the connection through "inheritance" will be damaged.

OK. In ASP. NET 2.0 Beta1, we can finally achieve the separation and connection between the page file and the Code-Behind file in a more elegant way. With the new language feature of partial class, we can finally get rid of clever, but clumsy inherited connections. To reflect the features of the background Code file in Beta1, we simply call the background Code file Code-Beside.

At the top of the page file, a statement is made as shown below:

<% @ Page Language = "C #" CompileWith = "Default. aspx. cs" ClassName = "Default_aspx" %>

Note that VS. NET does not provide us with a means to compile all the Code-Beside files into A. dll in/bin.

During deployment, we directly copy all the page files and Code-Beside files to the server. When a user browses a page, the ASP. NET engine automatically generates a partial Class Based on the content on the page, and then integrates it with the partial class in Code-Beside to complete the compilation. This compilation process (page file and Code-Beside) is completely completed dynamically at runtime. If we modify the page file or Code-Beside file, no manual operation is required, ASP. NET engine will automatically re-compile the next time you browse.

Well, of course, many people may feel uncomfortable. "Why should I deploy the background code file ?" Therefore, ASP. NET Beta1 also provides other compilation and deployment solutions, such as compiling all the content of the entire site, including the page file and the Code-Beside file, into one. dll, and then deploy it on the server.

Finally, let's take a look at the changes in the page compilation model in ASP. NET Beta2.

The Declaration at the top of the page file is as follows:

<% @ Page CodeFile = "Default. aspx. cs" Inherits = "Default_aspx" %>

How is it? Seeing "Inherits", do you doubt that you are going back to ASP. NET 1.1? Yes, no.

When. when creating a page. NET will automatically create a Code-Behind (we will re-use the word Code-Behind) file, when we add a control on the page,. NET, like Beta1, does not add a declaration in Code-Behind. However, when we compile the site,. NET automatically generates a "temporary intermediate" partial class based on the content of the page file, and then compiles the partial class and the partial class in Code-Behind to generate. dll file.

During deployment, we deploy/bin and all page files on the server just like ASP. NET 1.1. ASP. NET engine generates a class file based on the page content, and then according to the "Inherits" value declared in the file header, let this class file inherit from the specified parent class, and finally complete the compilation process.

In short, the page compilation model of Beta2 absorbs ASP. NET 1.1 and ASP. NET 2.0 Beta1 advantages. We can compile all the background code of the site, deploy it together with all the page files, and obtain Beta1, during development, there is no need to declare the benefits of page control objects in the background code file.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.