ASP.Net动态切换母版页 [英] ASP.Net Dynamically switch Master Pages

查看:166
本文介绍了ASP.Net动态切换母版页的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

从不需要使用前要做到这一点,但它可以动态地设置/更改该母版页页面被使用?有我创建了一个新的引导模板老asp.net web表单的项目,但老板希望给人们的机会,在新的切换迫使它在他们身上,而不是

Never needed to do this before but is it possible to dynamically set/change which master page a page is using? Have an old asp.net web forms project which I have created a new bootstrap template for but the boss wants to give people the opportunity to switch on the new one instead of forcing it upon them.

推荐答案

我会建议你创建一个BasePage类,比写在这个类中此方法并继承所有的网页从这个类的母版页可以动态改变。

I would recommend you to create a BasePage class than write this method in that class and inherit all of your pages from this class whose master page can be changed dynamically.

public class BasePage: System.Web.UI.Page
{
protected void Page_PreInit(object sender, EventArgs e)
{
    try
    {
        if (conduction1)
            this.Page.MasterPageFile = "~/MasterPage.master";
        else
            this.Page.MasterPageFile = "~/Master.master";

    }
    catch (Exception ex)
    {

    }
}
}

然后在从你的BasePage继承页页这样

And then in your page inherit page from BasePage like this

public partial class _Default:BasePage

这篇关于ASP.Net动态切换母版页的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆