母版页可以引用具有相同内容和 contentplaceholder 标记的另一个母版页吗?

发布于 2024-10-11 09:45:08 字数 1232 浏览 1 评论 0原文

当前设置

我目前在以下层次结构中拥有三个母版页和内容页:

  • 一个显示最终结果的根级母版页。将此称为“A”
  • 两个兄弟页面不互相引用,但包含所有相同的 contentplaceholder 元素,只是顺序不同,周围有不同的
    。两者都引用根级主页。将它们称为“B1”和“B2”。
  • 引用上述一个或其他同级母版页(不是两者)的多个内容页。将这些称为“C1”到“C-随便”。

基本上我有:

Cn =>; B1 =>一个

厘米=> B2 =>一个

这个层次结构工作得很好。

所需的设置

我想要做的是在内容页面和同级母版页之间的层次结构中添加一个新级别(新的母版页)。基本上是这样的:

  • 一个显示最终结果的根级母版页。
  • 两个同级页面加上第三个同级页面。将其称为 B3
  • 新的中间母版页,它动态“选择”同级母版页之一。期望的行为是将 C 给出的内容直接传递给 Bn 而不对其进行修改。 D 唯一主动做的就是选择哪个 Bn。将此新母版页称为 D。
  • 几个内容页面引用新的中间母版页而不是旧的同级页。

对此的挑战是,我正在一个相当复杂的产品范围内工作,并且我无法更改原始的两个同级母版页(B1 和 B2)或内容页面( C)以任何有意义的方式。

我想:

Cn =>; D=> B1=>一个

厘米=> D=> B2 =>一个

CK => D=> B3 =>一个

本质上,D 应该将其所有内容“传递”到它选择的任何 B 级母版页。我无法将这个逻辑放在 C 级页面中。

其他详细信息

  • 所有 B 级页面都具有相同的内容/内容占位符标签,只是顺序和样式不同。
  • D 可以很复杂,只要它不需要修改 C 或 B。
  • 我正在使用 ASP.Net 2.0

这可能吗?

Current Setup

I currently have three masterpages and content pages in the following hierarchy :

  • One root-level masterpage that displays the final result. Call this "A"
  • Two sibling pages that don't reference each other but contain all the same contentplaceholder elements, just in a different order with different <div>'s surrounding them. Both reference the root-level masterpage. Call these "B1" and "B2".
  • Several content pages that reference one or the other sibling master pages above (not both). Call these "C1" through "C-whatever".

Basically I have:

Cn => B1 => A

Cm => B2 => A

This hierarchy works fine.

Desired Setup

What I want to do is add in a new level to this hierarchy (a new master page) between the content pages and the sibling masterpages. Basically so it's like this:

  • One root-level masterpage that displays the final result.
  • Two sibling pages plus a third sibling. Call it B3
  • A new middle masterpage that dynamically 'chooses' one of the sibling masterpages. The desired behaviour is to pass through the content given by C directly to Bn without modifying it. The only thing D actively does is choose which Bn. Call this new masterpage D.
  • Several content pages that reference the new middle master page instead of the old siblings.

The challenge to this is, I'm working within the confines of a rather complex product and I cannot change the original two sibling masterpages (B1 and B2) or content pages (C) in any meaningful way.

I want:

Cn => D => B1 => A

Cm => D => B2 => A

Ck => D => B3 => A

Essentially, D should "pass through" all it's content to whichever B-level masterpage it chooses. I can't put this logic in the C-level pages.

Additional Details

  • All B-level pages have the same content/contentplaceholder tags, just ordered and styled differently.
  • D can be as convoluted as it has to be, so long as it doesn't require modifying C or B.
  • I'm using ASP.Net 2.0

Is this possible?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

初见你 2024-10-18 09:45:08

MasterPage 没有 Page_PreInit 事件,因此对 MasterPage 层次结构(嵌套或其他方式)的所有更改都必须源自内容页。

因此,如果您可以修改内容页面,请添加:

void Page_PreInit(object sender, EventArgs e)
{
    //if (someCondition)
        this.Master.MasterPageFile = "~/Path/B1.master";
    //else if (otherCondition)
        this.Master.MasterPageFile = "~/Path/B2.master";
    //etc.
}

A MasterPage doesn't have a Page_PreInit event, so all changes to the MasterPage hierarchy (nested or otherwise) must originate from the content page.

So, if you can modify the content pages, add:

void Page_PreInit(object sender, EventArgs e)
{
    //if (someCondition)
        this.Master.MasterPageFile = "~/Path/B1.master";
    //else if (otherCondition)
        this.Master.MasterPageFile = "~/Path/B2.master";
    //etc.
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文