Page Life Cycle and Control Loading
Here in this article emphasis is on
§ How Page Loading along with the Control Hierarchy loading occurs hand in hand.
§ In which phase the controls are completely created & initialized with their Default values & Post back values.
§ How View state comes in picture.
· For this read the article ‘Myth regarding View State’
For Digramatic View - http://arun-ts.blogspot.com/search/label/Diagrams
We’ll go thru below phases.
Stage 0 – Instantiation –
Creates The Page's Control Hierarchy & Assigns the decalrative properties to the Web Controls.
§ When the life cycle of the ASP.NET page begins, ASP.NET engine Instantiates an Auto-Generates Class that represents the requested ASP.NET Web page.
§ The purpose of this autogenerated class is to programmatically create the Page's Control Hierarchy. i.e Programmatically creating the Web controls specified in the page's HTML portion.
§ This is done by translating the HTML portion into a series of Programmatically-Created Web controls. i.e Translating—<asp:WebControlName Prop1="Value1" ... />—into the class's programming language.
§ In addition to the Web control syntax being converted into the appropriate code, the HTML markup present in the ASP.NET Web page's HTML portion is translated to Literal controls.
§ If you created your ASP.NET Web page using the code-behind technique, this autogenerated class is derived from the page's associated code-behind class [System.Web.Ui.Page].
§ In either case, this autogenerated class, along with a compiled instance of the class, is stored in the WINDOWS\Microsoft.NET\Framework\version\Temporary ASP.NET Files folder, in part so that it Doesn't Need To Be Recreated for each page request.
§ When the control hierarchy is constructed, the properties that are explicitly set in the declarative syntax of the Web control are assigned in the code.
Stage 1 – Initialization
§ After the control hierarchy has been built, in this the Page and its controls fire their Init events.
§ With regards to view state it is important for two reasons.
· First, server controls don't begin tracking view state changes until right at the end of the initialization stage.
· Second, when adding dynamic controls that need to utilize view state, these controls will need to be added during the Page's Init event as opposed to the Load event.
Stage 2 -
§ The load view state stage only happens when the page has been posted back.
§ During this stage, the view state data that had been saved from the previous page visit is loaded and recursively populated into the control hierarchy of the Page.
Stage 3 - Load Postback Data
§ The load postback data stage also only happens when the page has been posted back.
§ A server control can indicate that it is interested in examining the posted back data by implementing the IPostBackDataHandler interface
Stage 4 - Load
§ This is the stage with which all ASP.NET developers are familiar
Stage 5 - Raise Postback Event
§ There are two flavors of postback events.
· Changed event - DropDownLists SelectedIndexChanged event, or the TextBox's TextChanged event
· Raised event - Button Web control Click, Calendar control VisibleMonthChanged event
Stage 6 -
§ In the save view state stage, the Page class constructs the page's view state, which represents the state that must persist across postbacks.
Stage 7 - Render
§ In the render stage the HTML that is emitted to the client requesting the page is generated.
§ The Page class accomplishes this by recursively invoking the RenderControl() method of each of the controls in its hierarchy.
Thanks & Regards,
Arun Manglick || Tech Lead