How to change the Master Page dynamically

前端 未结 2 1875
野的像风
野的像风 2021-02-06 16:10

I want to assign one master page dynamically for a pure aspx file, Anybody can tell me, how to do this?

相关标签:
2条回答
  • 2021-02-06 17:05

    You can override OnPreInit in your default.aspx.cs and set the master page based on some value in your querystring. Something like this:

    protected override void OnPreInit(EventArgs e)
        {
            base.OnPreInit(e);
            if (Request.QueryString["Master"] == "Simple")
                MasterPageFile = "~/Masterpages/Simple.Master";
        }
    

    EDIT: the cause of your error message might be covered by this question.

    0 讨论(0)
  • 2021-02-06 17:12

    I Left the ContentPlaceholder to add on it.. Actually , I tried to assign master page without using ContentPlaceHolder.. Now, I realised that, atleast one ContentPlaceholder should be there temporarily, even though we will change the master page dynamically...

    0 讨论(0)
提交回复
热议问题