[asp.net tutorial] three. Web Forms programming Model

Source: Internet
Author: User
Tags control label documentation html tags
Asp.net|web| Programming | tutorials
1. Web Forms Programming Model

The user interface in Web forms is described by both HTML and server controls. Each control label corresponds to the actual object on a server.

The event that the control triggers is handled on the server side. Asp. NET "blends" the client with the server-side processing and looks as if the event was triggered and handled at the same end, and the fact that the client event caused the browser to generate a postback, the server-side object triggers the event.

The server-side code in the <script></script> block is not called a script, it is compiled and run, rather than interpreted, so it performs much more efficiently than an ASP script.

The runat= "Server" attribute in the label is the key to the ASP.net page, which lets the server "execute" the label instead of returning the label text to the client, so you must add runat= "Server" on the label that requires asp.net processing.
2. Web Controls

The Textbox,button,label in the previous example are Web controls. They are server controls defined in the System.Web.UI.WebControls namespace, and other specific controls can refer to the. NET Framework SDK documentation, which can be used in asp.net Web forms, with simple controls. such as label, there are also quite complex controls, such as the DataGrid.
3. HTML controls

HTML controls are another type of server control for ASP.net, defined in the System.Web.UI.HtmlControls namespace, and refer to the. NET Framework SDK documentation, which is typically added to the regular HTML tags runat= " Server, such as <input type= "text" runat= "server"/> is actually a System.Web.UI.HtmlControls.HtmlInputText object, virtually every Web The <form runat= "server"/> tag in a form is an HTML control.
4. Page Events

Not only can the server control trigger the event, the page can also.

First, what is a page before you introduce the page event? The following describes the process of asp.net handling doadd.aspx:

1 The system creates a temporary file that contains a class derived from System.Web.UI.Page that represents a Web page.
2) ASP. NET puts the code generated from the ASPX file into the class that you just generated. Where the Add method is called a member of the build class.
3 This class is compiled into a DLL file and stored in a system folder. Future requests will use this DLL file directly, without repeating 1, 2 steps unless the source file has been changed.
4 when requesting the page, ASP. NET instantiates this derived class and then "executes" it, the Page object instantiates all of its controls and sends their output to the browser.
If you installed the. NET Framework SDK 1.1, you can view this process by looking at the following diagram:
Ms-help://ms.netframeworksdkv1.1.chs/cpguidenf/html/vbderivedpagebaseclasstowebformoutput.gif

The. NET Framework SDK documentation describes all the events for the page class, and here is only a few important
Page.load Events
The Page.load event is triggered when the page loads, and we usually use the Page.IsPostBack property in the Load event handler to determine whether the page is loaded the first time or after the postback is generated. IsPostBack is a very important attribute, and if IsPostBack is true, a postback is generated and, in general, does not need to initialize the control at postback, ASP. NET retains control state.
Page.Init Events
The Page.Init event fires when the page is initialized, and postback does not trigger, so you can initialize the control here, connect the event handlers, and so on.
Page.prerender Events
The PreRender event is triggered when the page is finished and is about to be rendered, where the end action of the page can be processed.
5. Page instruction
Page directives can be used in ASPX files, although the standard practice is to include instructions at the beginning of a file, but they can be anywhere in the file. Each instruction can contain one or more attributes that are specific to that directive.

@page is the most commonly used one in all page directives, for example:

Code:
<%@ Page language= "C #"%>
This instruction sets the language of all embedded code. Like what:

HTML Code:
<body>
Now time: <% Response.Write (DateTime.Now.ToString ()); %>
</body>

@Page can only appear once on a page

@Import directive can import a namespace for a page, for example:

Code:
<%@ Import namespace= "System.Data"%>

Equivalent to C # code:

Code:
Using System.Data;

@Import instructions can appear multiple times

There are many other instructions, there are many attributes that are not available, and there is no way to describe them in detail, please refer to the related sections of the. NET Framework SDK documentation.

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.