Asp.net code hidden encoding model

Source: Internet
Author: User
Tags control label

I. inlineCodeHide with code
Advantages of the Code hiding model over Inline code:

1. The separation of logical code and HTML allows us to focus more on the processing of business logic.
2. Make the business logic clearer.
3. You can compile the post code into a DLL so thatProgramMore secure.

Ii. Relationship and mechanism between post code and pages
Three classes related to the post-code model.

1. Base page class

In the. NET class library, the page class defines the basic functions of the page. For example, you can store other controls, render HTML, and provide access to Asp.net objects (such as request, response, and session ).

2. Code post class
During compilation, Asp.net used the magic function of the Division class to append some additional code to the Code post class.

In the additional code, all controls on the page are defined as protected variables, so that they can be accessed in the Post-code class.

3. Page class

The Asp.net compiler creates another class to represent the actual ASPX page during compilation. This class inherits from the hidden class of code.
This class contains the initialization control and HTML Rendering code. When receiving this page request, Asp.net instantiates this class.
The relationships between these three types are as follows:

3. code hidden file and page connection
<% @ Page Language = "C #" autoeventwireup = "true" codefile = "default. aspx. cs" inherits = "_ default" %>
The connection between the code hidden file and the page is very simple, and the connection between them is completed in such a sentence at the top of the ASPX page.
Codefile specifies the post-code file, and inherits specifies the Class Name of the Post-Code that has been compiled.

Iv. Connection Between controls and page Variables

After understanding the relationship between the post-code class and the page class, it is much easier to understand how the control connects to the page variable.
For example:
<Asp: textbox id = "textbox1" runat = "server"> </ASP: textbox>
The Asp.net compiler attaches the following variable declarations to your code's post class. Of course, these declarations are invisible:

Protected system. Web. UI. textbox textbox1;
In this way, the page control label can be accessed in the Post-code class.
5. Connection between events and event handlers
In. net, the event mechanism is a very important mechanism, and this part is coming to be clarified later.

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: info-contact@alibabacloud.com 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.