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.