locked
Select master page at run time RRS feed

  • Question

  • User1497749907 posted

    Hi Guys 

    I have two websites, like to use one program for both sites,

    but I dont know how to select masterpage during run time. Is it possible to select master page at run time?

    Thanks.

    Dost

     

    Monday, May 12, 2008 7:34 PM

Answers

  • User-2110683555 posted

    Hi, it is possible to change Theme and Masterpage dynamically.

    But they have to be done on Page_Preinit Event like this

    page.masterpagefile ="~/SecondMaster.master"

    page.Theme = "SecondDefaultTheme"

    Hope this helps.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, May 12, 2008 10:33 PM
  • User2056512907 posted

    hi mate,

     

    You can use the prerender event of an page to change the MasterPage at runtime.

    cheers mate

    [Yes]

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, May 13, 2008 3:37 AM

All replies

  • User-2110683555 posted

    Hi, it is possible to change Theme and Masterpage dynamically.

    But they have to be done on Page_Preinit Event like this

    page.masterpagefile ="~/SecondMaster.master"

    page.Theme = "SecondDefaultTheme"

    Hope this helps.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, May 12, 2008 10:33 PM
  • User-1856974186 posted

    You can also do this globally. There are sample applications at http://ipona.com/temp/ThemesCS.zip and http://ipona.com/temp/ThemesVB.zip (same app,, different languages) that show how to apply both a theme and a master page at run time.

    Tuesday, May 13, 2008 3:31 AM
  • User2056512907 posted

    hi mate,

     

    You can use the prerender event of an page to change the MasterPage at runtime.

    cheers mate

    [Yes]

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, May 13, 2008 3:37 AM
  • User-1856974186 posted

    hi mate,

     

    You can use the prerender event of an page to change the MasterPage at runtime.

    cheers mate

    Yes

    No you can't. The master page can only be set before, or in, the PreInit event. PreRender is too late in the page lifecly and the controls have already been addy to the page.

    Tuesday, May 13, 2008 3:48 AM
  • User914590620 posted

     hi...

    you can change it like this... 

    protected void Page_PreInit(object sender, EventArgs e)
        {

    string MasterPage=null;

    //if u have session variable for check
    MasterPage  = Session["MasterPage"].ToString();

    //And if u are checking it from web.confiq value

    MasterPage=System.Configuration.ConfigurationManager.AppSettings.Get("MasterPage").ToString() ;

     

    if (MasterPage == "1") //check the user weather user is logged in or not<o:p></o:p>

                this.Page.MasterPageFile = "First.master";<o:p></o:p>

            else<o:p></o:p>

                this.Page.MasterPageFile = "Second.master";<o:p></o:p>

        }

     

    Tuesday, May 13, 2008 3:56 AM
  • User1497749907 posted
    Thanks every one for help i used this technique (dinesh_sp) with little change in c#

    Page.MasterPageFile = "~/zzzzzz.master";

    Thanks.

    Tuesday, May 13, 2008 5:41 PM
  • User1095738331 posted
    Where in the global asax file would be best?
    Sunday, October 5, 2008 3:01 AM
  • User-1856974186 posted

    See the Dynamic Themes and Master Pages demo projects at the bottom of this page: http://ipona.com/samples/default.aspx. This will show you how to do it.

    Sunday, October 5, 2008 6:38 AM