我可以动态改变嵌套母版页的主? [英] Can I change a nested master page's master dynamically?

查看:126
本文介绍了我可以动态改变嵌套母版页的主?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好了,我们都知道在页面的在preINIT事件动态更改母版页。

Okay, so we all know about changing a master page dynamically in a page's OnPreInit event.

但对于嵌套母版页?我可以改变一个大师的大师?

But what about a nested master page? Can I change a master's master?

有在母版类不会暴露在preINIT事件。

There is no OnPreInit event exposed in the MasterPage class.

任何想法?

推荐答案

刚刚测试过这一点,它从页面的preINIT正在使用嵌套母版的作品。

Just tested this and it works from the PreInit of the Page that is using the nested MasterPage.

protected void Page_PreInit(object sender, EventArgs e)
{
    this.Master.MasterPageFile = "/Site2.Master";
}

显然,你需要确保ContentPlaceholderIds跨你之间交换的页面保持一致。

Obviously you will need to ensure that the ContentPlaceholderIds are consistent across the pages you are swapping between.

这篇关于我可以动态改变嵌套母版页的主?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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