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:
- 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.