Thursday, April 28, 2011

Setting a master page's master page programmatically

Is there anyway to set a Master Page's Master Page programmaticly? Would I need to do this on each page? I don't have access to the pre_init event from Master. Hrm...

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

    Working with ASP.NET Master Pages Programmatically

  • In the PreInit function place:

    this.MasterPageFile = "~/masterPage.master";
    

    Yes, you will need to put this on each page. To get aroud it, have all the pages inherit from a base Page and place put the master page reference there.

    Shawn Simon : this is the route im going with, so it will look like me.master.masterpagefile

0 comments:

Post a Comment