Monday, 10 November 2014

sequence of events in master page and content page

In your application if you are using Master page, Content Page (Child Page) and User controls. Page life cycle for different pages have different events. Below content you can see the  Sequence of events for Master Page, Content Page and User Controls.

Problem: Why its required?
Many time its happen that you need the value of master page into Child page or the user control page into Webpage. Then from below description you will know that what is the possibility.

Creating the three file in application.
1. Site1,Master
2. WebForm1,aspx
3. WebUserControl1.aspx

Place the below code for each of the pages 

1. Site1.Master : Write the code for master page;
Implementing Init, Load and Pre-render event of Master page.

2. WebForm1.Aspx: Write the code for Content Page;
Implementing Init, Load and Pre-render event of page.

3. WebUserControl1.Ascx: Write the code for User Control;
Implementing Init, Load and Pre-render event of User Control.

Run Your application and see the content written in the pages into Browser; You can easily identify which will call into the sequences.  Which vents will call the first between Master Page, Content page and User controls.

Now Its clear from the above screen that the sequence is like below for events
1. User Control init
2. Master Page init
3. Content page init

4. LOAd Content page Load
5. LOAd Master Page Load
6. LOAd User Control Load

7. Content page Render
8. Master Page Pre Render
9. User Control Render  

No comments:

Post a Comment