【问题标题】:Filling in parent master page from child从孩子填写父母版页
【发布时间】:2009-05-28 17:02:32
【问题描述】:

我想要一个使用子母版页的页面,填写父级的内容占位符,但我无法让它工作。每当我尝试时,都会收到错误消息“在母版页 '/templates/info.master' 中找不到 ContentPlaceHolder 'customHead',请在内容页面中验证内容控件的 ContentPlaceHolderID 属性。”

我有一个这样定义的母版页 (/templates/main.master):

<%@ Master Language="C#" %>
<head runat="server">
    <title>foo</title>
    <asp:contentplaceholder runat="server" id="customHead" />
</head>
<body>
    <div id="content">
        <asp:contentplaceholder runat="server" id="masterContent" />
    </div>

然后我有一个这样定义的子主 (/templates/info.master):

<%@ Master Language="C#" MasterPageFile="/templates/main.master" %>
<asp:content id="homeContent" contentPlaceHolderId="masterContent" Runat="server">
<div id="info-container">
    <div id="info-content">
        <asp:contentplaceholder runat="server" id="infoContent"/>
    </div>
</div>
</asp:content>

最后我的页面是这样定义的:

<%@ Page Language="C#" MasterPageFile="/templates/info.master" %>
<asp:Content ID="head" ContentPlaceHolderID="customHead" runat="server">
    <!-- Custom header area -->
    <link rel="stylesheet" type="text/css" href="foo.css"/>
</asp:Content>
<asp:Content ID="content" ContentPlaceHolderID="childContent" runat="server">
    This is my child content
</asp:Content>

【问题讨论】:

    标签: asp.net master-pages


    【解决方案1】:

    您没有在子母版页中定义“customeHead”。如果要公开根母版页内容区域,则需要在子母版页中公开它。

    <%@ Master Language="C#" MasterPageFile="/templates/main.master" %>
    <asp:contentplaceholder runat="server" id="customHead" />
    <asp:content id="homeContent" contentPlaceHolderId="masterContent" Runat="server">
        <div id="info-container">
            <div id="info-content">
                <asp:contentplaceholder runat="server" id="infoContent"/>       
            </div>
        </div>
    </asp:content>
    

    【讨论】:

    • 在那里添加占位符只会给我这个错误:“解析器错误消息:仅允许直接在包含内容控件的内容页面中使用内容控件。”
    • @Zachary,我认为你基本上是对的,你只需要在 info.master 页面上的另一个内容控件中嵌入一个 contentplaceholder 控件:
    • 添加了 Mxyzptlks,它就像一个魅力。谢谢你们!
    【解决方案2】:

    您是否使用this.Page.Master 进行设置?

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-08-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-01-24
      • 1970-01-01
      • 2019-11-24
      相关资源
      最近更新 更多