Asp. NET Learning note--webform page life cycle

Source: Internet
Author: User

WebForm Operating principle

The principle of operation is the same: ASPX and ashx run the same mechanism.

Operating principle different points:

1. When executing the event pipeline, the foreground page class object was created between 7 and 8 events, and when was the background class created? Because the ASPX foreground page inherits from the background, the background is created when the foreground page class is created.

2. Between the 11th and 12 events, invoking the ProcessRequest method of the foreground page class object stored in the Remaphandler will perform complex processing, that is, walking the page life cycle.

WebForm page life cycle

1. Check the foreground class code by decompile

Front desk Code p01index.aspx

<%@ Page language="C #"autoeventwireup="true"Codebehind="P01Index.aspx.cs"inherits="Website.p01index"%><<%@ Import namespace="WebSite"%><! DOCTYPE html>"http://www.w3.org/1999/xhtml">"Content-type"Content="text/html; Charset=utf-8"/> <title></title> <script runat="Server"> Public stringGetValue (stringinputstr) {            return "you have entered:"+ Inputstr +"overridden by a method with the same name as the foreground page class"; }    </script>"Form1"runat="Server"> <div>View the Assembly of the page class where the current foreground page is compiled:<%= This. GetType (). Assembly.location%><br/>Name= <%=name%><br/> Age=<%= Age%> <br/>To call a non-private method:<%= GetValue ("Eight Commandments")%><br/>Name= <% Response.Write (Name); %> <%if(Age > -) {Response.Write ("more than 30."); }                Else{Response.Write ("you can still play for years ."); }                                stringres = kits. GetInput ("haha"); Response.Write ("<br/>"+res); %> </div> <asp:textbox id="TextBox1"runat="Server"></asp:TextBox> <asp:button id="Button1"runat="Server"text="Button"/> </form></body>

1.1 How do I view the assembly of the page class where the current foreground page is compiled? This. GetType (). Assembly.location

2 code written in the foreground page is compiled into the _renderfrom1 method

3 methods in the page are compiled into a method in the foreground page class

4. Call the ProcessRequest method of the foreground page class object, this method invokes the ProcessRequest method of the parent class, and in the parent class method, calls this. FrameworkInitialize ();

4.1 frameworkinitialize () initializes the control tree based on the declarative nature of the page during page generation

4.2 Create a control tree, _buildcontroltree () inside is the entire page control tree structure is created, if it is normal C # code, it is compiled into a method body

4.3 The ProcessRequestMain method is called immediately after the parent class method, in which the main trigger is a series of events

4.4 By ViewState, determines whether the current request is a postback, and if ViewState is not NULL, then IsPostBack is true

4.5 ProcessRequestMain Method

4.6 This is called in the ProcessRequestMain method . Performpreinit ();

(1) Trigger PreInit Event

(2) The Personalization information and page theme (if any) will be loaded to initialize the master page.

4.7 This is called in the ProcessRequestMain method . Initrecursive (null);

(1) The Initrecursive method of calling the base class is initialized with a recursive child control, such as generating a control ID and setting the page property of the control.
(2) The Init event will be triggered at this time

4.8  this . Oninitcomplete (Eventargs.empty); initcomplete event is triggered

4.9 this. Loadallstate (); Load page State resolution ViewState, ViewState in page form Base64 encoded, deserialized, in the ViewState attribute of the page

4.10 this ); Set the control data submitted by table Dropdowns to the property of the corresponding control in the control tree of the Page object

4.11 this. Onpreload (Eventargs.empty); Preload event is called

4.12 loadrecursive () is called, the Load event of the page is first triggered, immediately after the control's load event is triggered, the Page_Load method is the method that responds to the Load event, so the Page_Load method is executed at this time

4.13 this. Processpostdata (This._leftoverpostdata, false); Assign a value to a new control added in Page_Load (value from form submission)

4.14 this. Raisechangedevents (); performs a control non-click postback event, such as a DropDownList in a page

 

4.15 this. RaisePostBackEvent (this. _requestvaluecollection); perform a control click on a postback event, such as a button

4.16 this. Onloadcomplete (eventargs.empty); triggering loadcomplete events

4.17 this. Prerenderrecursiveinternal (); PreRender event is triggered

4.18 this. Performprerendercomplete (); Prerendercomplete event is triggered

4.19 this. Saveallstate (); Save the property state of the control in the viewstate of the page

4.20 this. RenderControl (this. Createhtmltextwriter (this. Response.Output)); ; recursively invokes the render of each control in the control tree to generate HTML code for the entire page

Finally, the last big picture of the whole

Resources

1. Intelligence Podcast

2.http://www.knowsky.com/897396.html

3.http://www.3fwork.com/b101/000785mym001797/

Asp. NET Learning note--webform page life cycle

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.