Master Pages 101: Using VB 2005 to Work With Event Firing Order

Master pages and the content pages based on them share a number of events and it's important to know the order in which those events fire. Here is a list of the events in their firing order.

Content Page Pre Initializes

Master Page Child Controls Initialize

Content Page Child Controls Initialize

The Master Page initializes

The Content Page initializes

The Content Page Initialize Complete

Content Page Pre Loads

Content Page Loads

Master Page Loads

Master Page Child Controls Load

Content Page Child Controls Load

Content Page Load Complete

Knowing when these events fire is important because there are things you can only do at certain times in the page creation process. For example, take a look at the following code:

    Protected Sub Page_PreInit(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.PreInit
        Me.MasterPageFile = "MasterPage3.master"
    End Sub

This code programmatically assigns the master page to be used to construct the content page. Obviously this needs to happen very early in the page creation process and that's why it's in the Page_PreInit.

posted on Monday, June 4, 2007 10:51 PM Print
Comments are closed.
Comments have been closed on this topic.