Programmatically setting MasterPageFile for an @ Master

  • Thread starter Greg Collins [Microsoft MVP]
  • Start date
G

Greg Collins [Microsoft MVP]

I'm looking to discover in what event I can programmatically set this.MasterPageFile for a master page.

Documentation states that this property must be set in the PreInit or before, but master pages don't have a PreInit event -- just an Init event.

So what event is available to a master page that comes before PreInit that can be used to programmatically set the MasterPageFile property?

Thanks in advance!
 
D

David R. Longnecker

Perhaps I'm reading this wrong, but wouldn't/couldn't you set this in a page
and inherit it?

For example, if you have a BasePage that all of your other pages inherits.

~/App_Data/BasePage.cs contains:

public class BasePage : Page
{

public BasePage() : base()
{
base.PreInit += new EventHandler(Page_PreInit);
}

protected void Page_PreInit(object sender, EventArgs e)
{

this.MasterPageFile = "~/MasterPage.master";
}

---

~/Default.cs (code-behind for Default.aspx) contains the simple inheritance
of your BasePage:

public partial class _Default : BasePage
{

%code behind code%

}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,077
Latest member
SangMoor21

Latest Threads

Top