Setting an ASP.NET Master Page at runtime

前端 未结 6 1298
星月不相逢
星月不相逢 2021-02-04 15:45

I\'m working on a site which needs to be able to support two or more looks, changable at runtime. I\'d hoped to be able to handle the change with a CSS switch, but it looks like

6条回答
  •  眼角桃花
    2021-02-04 16:40

    Inherit all you pages from a base class like

    public class PageBase : System.Web.UI.Page
    {
        public PageBase()
        {
            this.PreInit += new EventHandler(PageBase_PreInit);
        }
        void PageBase_PreInit(object sender, EventArgs e)
        {
            this.MasterPageFile = "~/MyMasterPage.Master";
        }
    }
    

提交回复
热议问题