ASP. NET Server controls

Source: Internet
Author: User

ASP. NET server controls can be divided into two types, one is the Web server controls, located in the System. web. UI. in the WebControls namespace, the other type is the HTML Server Control, which is located in the System. web. UI. htmlControls namespace.

The Web server Control looks like this <asp: control_name runat = "server" ......>, the HTML server Control looks like this

So why is the control executed on the server after runat = "server" is added to the HTML Tag?

First, let's take a look at how the Web Server Control is added. First, add a Button-type control Button1 on the Default. aspx page.


Then open the Default. aspx. designer. cs file, and we will see the code that actually adds the Button1 object.

 

Similarly, we add the <p id = "p1" runat = "server"> </p> HTML tag to the page.

Then open the Default. aspx. designer. cs file again. The following code is added:


This is the truth behind the HTML server Control. When we add the runat = "server" attribute to the tag <p id = "p1"> </p>, the background code will create a server-side control HtmlGenericControl object p1.

In this way, we can understand why the HTML Tag becomes a server control simply after the attribute runat = "server" is added. This is because the actual control of this tag is an instance p1 of HtmlGenericControl.


The relationship between HTML tags and corresponding server controls is listed below


In the preceding example, the p tag belongs to "other HTML elements not specified by the specific HTML server control" and is controlled by the HtmlGeneric control. <A> labels or <input> and other labels all have specific server-side controls. The remaining ones include: most labels, such as <p> tag, <div> tag, and <span> tag, are controlled by the HtmlGeneric control.

After runat = "server" is added to the HTML Tag, the background code automatically adds the corresponding HTML server control object to make it a control executed on the server.

This is the secret behind the HTML Server Control.

The ASP. NET server Control also has a feature, that is, all server controls must be placed inside a <form runat = "server"> </form>.


The following is my summary of ASP. NET Server controls:

 

I hope this article will help my fellow ASP. NET beginners.

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.