Clear Asp.net (2): page class and page used as control container

Source: Internet
Author: User
Tags blank page

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

 

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.