【问题标题】:Multiple content holders in a master page母版页中的多个内容持有者
【发布时间】:2018-12-03 03:54:18
【问题描述】:

我在 VS 2008 中创建了一个简单的 Web 应用程序项目。我在其中添加了一个母版页。然后我添加了两个面板。在每个面板中,我添加了一个 ContentPlaceHolder。我为每个 ContentPlaceHolder 添加了一个 ContentPage。

当我使用 Vs 2008 内部网络服务器运行它时,没有显示任何内容持有者页面。有什么帮助吗?我怀疑我做错了什么。

谢谢。

代码如下:

<%@ Master Language="C#" AutoEventWireup="true" CodeBehind="Site1.master.cs" Inherits="WebApplication5.Site1" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title></title>
    <asp:ContentPlaceHolder ID="head" runat="server">
    </asp:ContentPlaceHolder>
</head>
<body>
    <form id="form1" runat="server">
    <asp:Panel ID="Panel1" runat="server" Height="300px" Width="200px" Style="z-index: auto;
        left: 0px; top: 0px; position: absolute">
        <asp:ContentPlaceHolder ID="ContentPlaceHolder1" runat="server">
        </asp:ContentPlaceHolder>
    </asp:Panel>
    <asp:Panel ID="Panel2" runat="server" Height="300px" Width="200px" Style="z-index: auto;
        left: 205px; top: 0px; position: absolute">
        <asp:ContentPlaceHolder ID="ContentPlaceHolder2" runat="server">
        </asp:ContentPlaceHolder>
    </asp:Panel>
    </form>
</body>
</html>




<%@ Page Title="" Language="C#" MasterPageFile="~/Site1.Master" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="WebApplication5.WebForm1" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
Content Page 1
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="ContentPlaceHolder2" runat="server">
</asp:Content>





<%@ Page Title="" Language="C#" MasterPageFile="~/Site1.Master" AutoEventWireup="true" CodeBehind="WebForm2.aspx.cs" Inherits="WebApplication5.WebForm2" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="ContentPlaceHolder2" runat="server">
Content Page 2
</asp:Content>

【问题讨论】:

  • 您能否向我们展示母版页和基于该母版页的内容页的 ASPX 标记??
  • 这个问题没有用,除非你指定标记。
  • 您的代码中的所有内容似乎都已准备就绪。当您运行应用程序时,它会转到 WebForm1.aspx 还是 WebForm2.aspx?或者您是否将其转到 default.aspx 之类的其他页面?
  • 我已经尝试了所有三个并得到相同的结果。它只显示一个 ASP 页面。

标签: asp.net


【解决方案1】:

愚蠢的问题:你有这个设置吗??

  • 在您的母版页上,您应该有两个具有不同 ID 的 &lt;asp:ContentPlaceHolder&gt;,例如

    <asp:ContentPlaceHolder id="placeHolder1" runat="server" />
    

    <asp:ContentPlaceHolder id="placeHolder2" runat="server" />
    
  • 在实际页面(基于该母版页)上,您应该有 &lt;asp:Content&gt; 引用母版页中定义的适当占位符:

    <asp:Content id="content1" ContentPlaceholderID="placeHolder1" runat="server">
       ....
    </asp:Content>
    

    <asp:Content id="content2" ContentPlaceholderID="placeHolder2" runat="server">
       ....
    </asp:Content>
    

你有这个吗??这才是应该的,真的。因此,当您在浏览器中显示实际数据页面时,您肯定会看到一些东西......

【讨论】:

  • 更新问题,请查收。
【解决方案2】:

确保您的 ContentPlaceHolder 和 Content 标签上都有 runat="server"

【讨论】:

  • 更新问题,请查收。
【解决方案3】:

代码如下:

<%@ Master Language="C#" AutoEventWireup="true" CodeBehind="Site1.master.cs" Inherits="WebApplication5.Site1" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title></title>
    <asp:ContentPlaceHolder ID="head" runat="server">
    </asp:ContentPlaceHolder>
</head>
<body>
    <form id="form1" runat="server">
    <asp:Panel ID="Panel1" runat="server" Height="300px" Width="200px" Style="z-index: auto;
        left: 0px; top: 0px; position: absolute">
        <asp:ContentPlaceHolder ID="ContentPlaceHolder1" runat="server">
        </asp:ContentPlaceHolder>
    </asp:Panel>
    <asp:Panel ID="Panel2" runat="server" Height="300px" Width="200px" Style="z-index: auto;
        left: 205px; top: 0px; position: absolute">
        <asp:ContentPlaceHolder ID="ContentPlaceHolder2" runat="server">
        </asp:ContentPlaceHolder>
    </asp:Panel>
    </form>
</body>
</html>




<%@ Page Title="" Language="C#" MasterPageFile="~/Site1.Master" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="WebApplication5.WebForm1" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
Content Page 1
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="ContentPlaceHolder2" runat="server">
</asp:Content>





<%@ Page Title="" Language="C#" MasterPageFile="~/Site1.Master" AutoEventWireup="true" CodeBehind="WebForm2.aspx.cs" Inherits="WebApplication5.WebForm2" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="ContentPlaceHolder2" runat="server">
Content Page 2
</asp:Content>

【讨论】:

  • 如需更新,请编辑您的原始问题,或为您的问题添加评论。不要发布更新作为答案。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-02-12
  • 1970-01-01
  • 1970-01-01
  • 2012-09-05
  • 1970-01-01
相关资源
最近更新 更多