Thursday, May 19, 2011

When you work with master pages and content pages, both can use the same events (such as Page_Load).Be sure you know which events come before others. You are bringing two classes together to create a singlepage class, and a specific order is required. When an end user requests a content page in the browser, the event ordering is as follows:

Master page child controls initialization:
All server controls contained within the master page are first initialized.
Content page child controls initialization: All server controls contained in the content page are initialized.
Master page initialization: The master page itself is initialized.
Content page initialization: The content page is initialized.
Content page load: The content page is loaded (this is the Page_Load event followed by the Page_LoadComplete event).
Master page load: The master page is loaded (this is also the Page_Load event).
Master page child controls load: The server controls on the master page are loaded onto the page.
Content page child controls load: The server controls on the content page are loaded onto the page.


How to access master page controls from content pages

Label headerLabel = (Label)
Master.FindControl("Header"); // Header is my master page label id.
headerLabel.Text = "This label content is set through the Page_Load event of the child page";

The following is the sequence in which events occur when a master page is merged with a content page:

1.Master page controls Init event.

2.Content controls Init event.

3.Master page Init event.

4.Content page Init event.

5.Content page Load event.

6.Master page Load event.

7.Content controls Load event.

8.Content page PreRender event.

9.Master page PreRender event.

10.Master page controls PreRender event.

11.Content controls PreRender event.

0 comments:

Popular Posts

Recent Posts

Unordered List

Text Widget