Refer: ASP.NET Page Life Cycle Overview
Page Event Typical Usage PreInit Restores after the start of the start phase and before the start of the initialization phase. Use this event for the following: Check the IsPostBack property to determine if this will be the first time the page is being processed. The IsCallback and IsCrossPagePostBack properties were also set at this time.
- Create or recreate dynamic controls.
- Dynamic installation of the main page.
- Set the Theme property dynamically.
- Read or set the value profile property.
Note If the request is a postback, the control values have not yet been restored from the view state. If you set a control property at this point, its value may be overwritten in the next event.
From: Dynamic connection of main pages
In addition to specifying the main page declaratively (in the @ Page directive or in the configuration file ), you can dynamically attach the main page to the content page. Since the main page and the content page are combined at the initialization stage of the page processing, the main page must be assigned before this. Usually you assign the main page dynamically during PreInit , as in the following example:
void Page_PreInit(Object sender, EventArgs e) { this.MasterPageFile = "~/DefaultMaster.master"; }
Edit:
Source: ASP.NET Master Pages - How Master Pages Work
You can also use the @Page directive to specify the main page.
<% @ Page Language="C#" MasterPageFile="~/Master.master" Title="Content Page 1" %>
source share