In this article I will show the loading process sequence of a Master Page that contains a Contents Page and that Contents Page has a User Control.
Step 1:
Create a website named "Loading_sequence".
Step 2:
Step 1:
Create a website named "Loading_sequence".
Step 2:
- Add a Master Page named "MatserPage.master" within it by right-clicking on the website in "Solution Explorer" then choose "Add" -> "Add New Item".
- Create some events in the ".cs" file of the Master Page and add a "response.write()" method with unique text for monitoring the process of execution.
- protected void Page_PreInit(object sender, EventArgs e)
- {
- Response.Write("Master Page Pre Init event called <br/> ");
- }
- protected void Page_Init(object sender, EventArgs e)
- {
- Response.Write("Master Page Init event called <br/> ");
- }
- protected void Page_Load(object sender, EventArgs e)
- {
- Response.Write("Master Page Load event called <br/> ");
- }
Step 3:
- Add a Contents Page named "Default.aspx" within it by the right-clicking on the website in Solution Explorer then choose "Add" -> "Add New Item" and check the "Select master page" checkbox to attach the Master Page.
- Select the Master Page name that you want to attach.
- Create some events in the ".cs" file of the Contents Page and add a "response.write()" method with unique text by which we can monitor execution as written in the Master Page.
- protected void Page_PreInit(object sender, EventArgs e)
- {
- Response.Write("Content Page Pre Init event called <br/> ");
- }
- protected void Page_Init(object sender, EventArgs e)
- {
- Response.Write("Content Page Init event called <br/> ");
- }
- protected void Page_Load(object sender, EventArgs e)
- {
- Response.Write("Content Page Load event called <br/> ");
- }
Step 4:
- Add a Web User Control named "WebUserControl.aspx" within it by right-clicking on the website in Solution Explorer then choose "Add" -> "Add New Item".
- Create some events in the ".cs" file of the Web User Control and add a "response.write()" method with unique text for monitoring the execution as written in the Master Page and the Contents Page.
- protected void Page_PreInit(object sender, EventArgs e)
- {
- Response.Write("User Control Pre Init event called <br/> ");
- }
- protected void Page_Init(object sender, EventArgs e)
- {
- Response.Write("User Control Init event called <br/> ");
- }
- protected void Page_Load(object sender, EventArgs e)
- {
- Response.Write("User Control Load event called <br/> ");
- }
Step 5:Add the Web User Control to the Contents Page then "Register Tag" and write the code to access the control by the "TagPrefix" and "TagName".
Step 6:Run the website to see the output.
Step 6:Run the website to see the output.
what's the page life cycle order of a control/page compared to a user contorl inside it?
Page: PreInit
Control: Init
Page: Init
Page: InitComplete
Page: PreLoad
Page: Load
Control: Load
Page: LoadComplete
Page: PreRender
Control: PreRender
Page: PreRenderComplete
Page: SaveStateComplete
Page: RenderControl
Page: Render
Control: RenderControl
Control: Unload
Control: Dispose
Page: Unload
Page: Dispose
When using master pages, the normal page event lifecycle is a little different. Here is the actual order: Page.OnPreInit MasterPageControl.OnInit (for each control on the master page) Control.OnInit (for each contol on the page) MasterPage.OnInit Page.OnInit Page.OnInitComplete Page.LoadPageStateFromPersistenceMedium Page.LoadViewState MasterPage.LoadViewState Page.OnPreLoad Page.OnLoad MasterPage.OnLoad MasterPageControl.OnLoad (for each control on the master page) Control.OnLoad (for each control on the page) OnXXX (control event) MasterPage.OnBubbleEvent Page.OnBubbleEvent Page.OnLoadComplete Page.OnPreRender MasterPage.OnPreRender MasterPageControl.OnPreRender (for each control on the master page) Control.OnPreRender (for each control on the page) Page.OnPreRenderComplete MasterPageControl.SaveControlState (for each control on the master page) Control.SaveControlState (for each control on the page) Page.SaveViewState MasterPage.SaveViewState Page.SavePageStateToPersistenceMedium Page.OnSaveStateComplete MasterPageControl.OnUnload (for each control on the master page) Control.OnUnload (for each control on the page) MasterPage.OnUnload Page.OnUnload - See more at: http://weblogs.asp.net/ricardoperes/asp-net-page-events-lifecycle#sthash.buRwyaHa.dpuf
Control: Init
Page: Init
Page: InitComplete
Page: PreLoad
Page: Load
Control: Load
Page: LoadComplete
Page: PreRender
Control: PreRender
Page: PreRenderComplete
Page: SaveStateComplete
Page: RenderControl
Page: Render
Control: RenderControl
Control: Unload
Control: Dispose
Page: Unload
Page: Dispose
When using master pages, the normal page event lifecycle is a little different. Here is the actual order: Page.OnPreInit MasterPageControl.OnInit (for each control on the master page) Control.OnInit (for each contol on the page) MasterPage.OnInit Page.OnInit Page.OnInitComplete Page.LoadPageStateFromPersistenceMedium Page.LoadViewState MasterPage.LoadViewState Page.OnPreLoad Page.OnLoad MasterPage.OnLoad MasterPageControl.OnLoad (for each control on the master page) Control.OnLoad (for each control on the page) OnXXX (control event) MasterPage.OnBubbleEvent Page.OnBubbleEvent Page.OnLoadComplete Page.OnPreRender MasterPage.OnPreRender MasterPageControl.OnPreRender (for each control on the master page) Control.OnPreRender (for each control on the page) Page.OnPreRenderComplete MasterPageControl.SaveControlState (for each control on the master page) Control.SaveControlState (for each control on the page) Page.SaveViewState MasterPage.SaveViewState Page.SavePageStateToPersistenceMedium Page.OnSaveStateComplete MasterPageControl.OnUnload (for each control on the master page) Control.OnUnload (for each control on the page) MasterPage.OnUnload Page.OnUnload - See more at: http://weblogs.asp.net/ricardoperes/asp-net-page-events-lifecycle#sthash.buRwyaHa.dpuf
No comments:
Post a Comment