有一种方法可以做到这一点,但如果您依赖占位符中的任何默认内容,则在某些情况下会出现小问题。
在您的示例中,您有 Parent1.master:
<div id="content">
<h1>Lorem Ipsum, from Parent1</h1>
<asp:ContentPlaceHolder ID="cphContent" runat="server">
<p>I am default content from Parent1...</p>
</asp:ContentPlaceHolder>
</div>
你还有一个嵌套的Parent2.master,它使用来自Parent1的占位符:
<asp:Content ContentPlaceHolderID="cphContent" runat="server">
<h2>I am some specific stuff from Parent2...</h2>
<asp:ContentPlaceHolder ID="cphContent" runat="server">
<p>I am default content from within Parent2!</p>
<p>We want to create another, nested CPH so that Parent3 can use it!</p>
<p>(It is seemingly OK that we can use the same ID for this CPH<br />
in Parent2 that we did originally in Parent1.)</p>
</asp:ContentPlaceHolder>
</asp:Content>
所以现在Parent3.master 可以使用来自 Parent2 的占位符。 (并且还为最终的内容页面提供了另一个占位符!)这里是:
<asp:Content ContentPlaceHolderID="cphContent" runat="server">
<h3>Hello from Parent3!</h3>
<asp:ContentPlaceHolder ID="cphContent" runat="server">
<p>I am more default text in yet another nested placeholder</p>
</asp:ContentPlaceHolder>
</asp:Content>
您呈现的内容页面将如下所示:
<div id="content">
<h1>Lorem Ipsum, from Parent1</h1>
<h2>I am some specific stuff from Parent2...</h2>
<h3>Hello from Parent3!</h3>
<p>I am the plugged-in content, from the content page!</p>
</div>
这种方法的一个很酷的地方是,为什么我们可能希望在整个继承链中为这些嵌套的 CPH 使用相同的名称,即您的最终内容页面可能会从使用父母版页 1 到 3 中的任何一个而更改,而无需改变任何东西,只要他们期望找到一个叫做cphContent的东西来消费。
好的,现在您已经看到了有趣的部分,但我提到的唯一可能是一个问题,即如果您试图让任何“默认”文本向下传递给任何孙子。我的意思是,如果您的内容页面没有为“cphContent”占位符提供任何内容,那么只会使用最后一个母版页中的默认值。 Parent1.master 的默认值在 Parent2 之后基本上丢失了。 (尽管您当然可以使用 Parent3 的默认设置。)可能有一种方法可以通过编程方式执行此操作,但是“开箱即用”这似乎允许您按照您的要求做,如果您可以接受这个警告的话。
祝你好运!