Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

When in the page lifecycle we can assign master page?

I know ViewState is available between InitComplete and Preload events in LoadViewSate method. Similarly, I want to know in which page lifecycle event can we assign a master page for a particular page?

like image 272
Shailesh Jaiswal Avatar asked Dec 26 '22 05:12

Shailesh Jaiswal


1 Answers

Because the master page and content page are merged during the initialization stage of page processing, a master page must be assigned before then. Typically, you assign a master page dynamically during the PreInit stage

On Page PreInit event

void Page_PreInit(Object sender, EventArgs e)
{
    this.MasterPageFile = "~/MyMaster.master";
}

Read Working with ASP.NET Master Pages Programmatically

like image 54
Damith Avatar answered Jan 09 '23 08:01

Damith