This section describes only part of the life cycle:
---referencing MSDN
Stage |
Description |
Page request |
Page requests occur before the page life cycle begins. When a user requests a page, ASP. NET determines whether the page needs to be parsed and compiled (thereby starting the life cycle of the page), or whether the cached version of the page can be sent in response without running the page. |
Begin |
At the beginning, page properties, such as request and response, will be set at this stage, and the page will also determine whether the request is a postback request or a new request, and set the IsPostBack property. Also, during the start phase, the UICulture property of the page is set. |
Page initialization |
During page initialization, the controls in the page can be used, and the UniqueID property of each control is set. In addition, any theme will be applied to the page. If the current request is a postback request, the postback data has not yet been loaded, and the control property value has not been restored to the value in view state. |
Load |
During load, if the current request is a postback request, the control property will be loaded with information recovered from view state and control state. |
Verify |
During validation, the Validate method for all validator controls is invoked, and this method sets the IsValid properties for each validator control and page. |
Postback event handling |
If the request is a postback request, all event handlers are called. |
Present |
View state is saved for the page and all controls before rendering. During the rendering phase, the page calls the Render method for each control, and it provides a text writer to write the output of the control to the outputstream of the Response property of the page. |
Unloading |
The unload is called when the page is fully rendered and the page has been sent to the client, and the page is ready to be discarded. At this point, the page properties (such as Response and Request) are unloaded and cleanup is performed. |
Program test page load Order
1 usingSystem;2 usingSystem.Collections.Generic;3 usingSystem.Linq;4 usingsystem.web;5 usingSystem.Web.UI;6 usingSystem.Web.UI.WebControls;7 8 namespaceOrder9 {Ten Public Partial classTestControls:System.Web.UI.Page One { A Static intCount =0; - //4 - protected voidPage_Load (Objectsender, EventArgs e) the { -Response.Write (Count +"----Page_Load <br/>"); -count++; - } + //0 - protected Override voidOnpreinit (EventArgs e) + { A Base. Onpreinit (e); atResponse.Write (Count +"----Onpreinit <br/>"); -count++; - } - //1 - protected Override voidOnInit (EventArgs e) - { in Base. OnInit (e); -Response.Write (Count +"----OnInit <br/>"); tocount++; + } - //5 the protected Override voidOnLoad (EventArgs e) * { $ Base. OnLoad (e);Panax NotoginsengResponse.Write (Count +"----OnLoad <br/>"); -count++; the } + //3 A protected Override voidonpreload (EventArgs e) the { + Base. Onpreload (e); -Response.Write (Count +"----Onpreload <br/>"); $count++; $ } - //6 - protected Override voidOnloadcomplete (EventArgs e) the { - Base. Onloadcomplete (e);WuyiResponse.Write (Count +"----Onloadcomplete <br/>"); thecount++; - } Wu //2 - protected Override voidOninitcomplete (EventArgs e) About { $ Base. Oninitcomplete (e); -Response.Write (Count +"----Oninitcomplete <br/>"); -count++; - } A protected Override voidOnUnload (EventArgs e) + { the Base. OnUnload (e); - } $ protected Override voidondatabinding (EventArgs e) the { the Base. OnDataBinding (e); theResponse.Write (Count +"----ondatabinding <br/>"); thecount++; - } in //7 the protected Override voidOnPreRender (EventArgs e) the { About Base. OnPreRender (e); theResponse.Write (Count +"----OnPreRender <br/>"); thecount++; the } + protected voidBtngraphics_click1 (Objectsender, EventArgs e) - { theResponse.Write (Count +"----Btngraphics_click <br/>");Bayi } the } the}
View Code
Operation Result:
0----Onpreinit
1----OnInit
2----Oninitcomplete
3----Onpreload
4----Page_Load
5----OnLoad
----Button_Click
6----Onloadcomplete
7----OnPreRender
Corresponding Event Analysis:
onpreinit: The PreInit event is raised when the method is called. The main thing in this event is to apply the theme in App_Themes , and to apply the master page, usually this step we don't need to do.
OnInit: initializes the control to which the page is applied, and then applies the applied themes to the control, and the Init method of the recursive triggering subspace
Oninitcomplete: Its invocation indicates initialization is complete, all controls are initialized, all themes have been applied
onpreload: Its invocation indicates that the page enters the loading state, in which the view state (??) is loaded for itself and all controls. ), and then process the request instance containing all the data that will be sent
OnLoad: Commonly used events, that is, the Page_Load event, Page_xxx is a kind of time link form for all time, such as Page_Init will call the OnInit method. This event can handle postback, because the view state, Themes, the child controls are already initialized, so it is easy for us to add logic without worrying about being overwritten by other events. It is important to note that the load order of any page is the first of its own, and then the child controls, such as: An ASPX page is called by the Load event, loaded itself first, and then loaded such as master pages, user controls, third-party server controls, and so on
onloadcomplete: indicates that the loading of all controls is complete . The next step is to render the loaded content
OnPreRender: This event handles some of the work that is prepared to render. For example, to DataBinda DataSource control, we can change the value of some controls dynamically on this event.
Onprerendercomplete: This event marks the readiness to render complete, the data has been finished binding
saveviewstate: In this event, the ViewState is serialized, and then the attempt state is saved in the page as a Input:hidden element
Render: at this stage, the framework invokes the Render method of all controls to render the page. To produce an HTML page
Unload: Uninstall after the end of the page life cycle
ASP. NET page Execution order (ASP. NET life cycle)