How to change the Master Page dynamically

巧了我就是萌 提交于 2019-12-09 05:04:36

问题


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


回答1:


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.




回答2:


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...



来源:https://stackoverflow.com/questions/1542629/how-to-change-the-master-page-dynamically

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!