I. Page class
All pages are inherited from the page class, and the page is instantiated as the control object. Therefore, all web forms are an instance of the page class.
Therefore, each blank page itself has implemented a large number of functions. You can see these methods and attributes through smart sensing in.
For example: findcontrol, registerstartupscript; ispostback, session, application, cache, request, response attributes, etc.
It is worth noting that the built-in objects such as session correspond to a property of the page class, which exposes instances with complete function classes.
For example, the session object is an instance of the system. Web. sessionstate. httpsessionstate class.
2. The page used as the control container
Web forms can be considered as a container for storing various controls. Various controls can also be seen as a container for storing other controls.
For example, the following HTML:
<Div> This is an HTML section. </div>
<Form ID = "form1" runat = "server">
<Asp: Panel id = "Panel1" runat = "server">
<Asp: linkbutton id = "linkbutton1" runat = "server"> linkbutton </ASP: linkbutton>
<Asp: textbox id = "textbox1" runat = "server"> </ASP: textbox>
</ASP: Panel>
<Asp: Label id = "label1" runat = "server" text = "label"> </ASP: Label>
</Form>
<Div> This is an HTML section. </div>
C # code:
Private void displaycontrols1 ()
{
Foreach (Control in this. Controls)
{
This. response. Write (control. GetType (). tostring () + "-- <B>" + control. ID + "</B> <br/> ");
}
}
Private void displaycontrols2 (controlcollection controls, int depth)
{
Foreach (Control in controls)
{
Response. Write (new string ('-', depth * 2) + "> ");
Response. Write (control. GetType (). tostring () + "-- <B>" + control. ID + "</B> <br/> ");
If (control. controls! = NULL)
{
Displaycontrols2 (control. Controls, depth + 1 );
}
}
}
The displaycontrol1 () method cannot completely control all servers on the page. It only traverses the first control in the page container.
In addition to the head, the following controls are traversed in order: literal -- htmlform -- literal
Asp.net uses the control object model for pages to Create HTML static content blocks as literalcontrol.
The displaycontrol2 () method can traverse all the server-side controls on the page. It can be seen from the code that each control can be considered as a container.
The page class has the CONTROLS attribute, and the control class also has the CONTROLS attribute.
Clear Asp.net series learning blog directory
Reference: Pro ASP. NET 3.5 in C #2008