Asp.net Control Development Study Notes (1)-control development Basics

Source: Internet
Author: User
Asp.net Control Development Study Notes (1)-control development Basics

Asp.netControl Development Learning notes-Control Development Basics(I)

Server Control Development Basics

When developing a server control, you must first understand its internal working mechanism. In fact, every HTML code returned by asp.net in the page, whether it is a simple <span> tag, a button, or a complex gridview control, is inherited from the System. web. UI. control object.

 

Control Properties

Most of the control methods are implemented through the control attributes. By controlling the server control attributes, you can change the html generated by the server accordingly.

The following describes the attributes of a server control:


In Visual Studio, when the properties of the control are changed through the Properties window, VS automatically adds the properties to the HTML of the corresponding aspx, while adding the properties in the html, the changed attribute view is also displayed in the Properties window, for example:

<Asp: Button ID = "Button1" runat = "server" Text = "Button"CommandName = "cName"/>

The Properties window is displayed, for example:

 


Of course, some controls have slightly different attributes, such as commonly used Label controls:

<Asp: Label ID = "Label1" runat = "server"> Text attribute </asp: Label>

The content between the start symbol and the end symbol is set to the Text attribute.

 

Of course, the most practical and commonly used method is to dynamically modify the properties of a control through C # programming.

 

Control Method

Controls use methods to operate more complex control operations. Generally, there are complicated processes within the control methods, including the combination of several internal functions and attributes. For example:

Private void LoadDropDownList ()

{

ArrayList list = new ArrayList ();

List. Add ("Hello ");

List. Add ("Goodbye ");

GridView1.DataSource = list;

GridView1.Databind ();

}

In this way, by calling the Databind () method, you can bind the gridview to the data source.

Control event

Controls use events to notify other classes or clients that a certain state is changed. An event is a flexible mechanism. When the control interacts with the client, the event interacts with the server through the Http Post method, and the automatic return mechanism is used, events in WEB development behave like developing a Windows FORM Program (of course, the speed is not comparable to that in Form)

In Visual Studio, you can use the yellow lightning icon in the Properties window to display and control the control events, as shown below:

After you double-click an event, a default processing method is generated in the background. The naming rule is "control name_event name"

 


WEB Page
Essentially a control tree

 

After the Trace = "true" is set to the Page in the header of the aspx Page, the Page displays the corresponding tracing information. In the Control Tree section, you will find that the entire page is actually a control tree ,:

 

Root control?

Okay. Since the essence of the asp.net page is a control tree, C # is a fully object-oriented language Convention (everything inherits from System. object), so what is the common parent class of all controls?

In asp.net, all controls are distributed in three major namespaces:

System. Web. UI

System. Web. UI. WebControls

System. Web. UI. HtmlControls

Shows the relationship between them.


System. Web. UI
Namespace

It can be seen that System. web. the UI is at the top of the inheritance tree, while the System. web. UI. control is the basis of all controls. All controls must inherit the Control class directly or indirectly, and the Page class and UserControl class must inherit the Control class directly.

 

System. Web. UI. HtmlControlsNamespace

In the System. Web. UI. HtmlControls namespace, by adding the runat = "server" attribute to the html Tag, the tag in HTML can be converted into a server control. The Asp.net engine matches the HTML tag in the page with the object in System. Web. UI. HtmlControls. System. Web. UI. HtmlControls namespace:

 

 

To be continued .........

 

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.