我在VS 2008中创建了一个简单的Web应用程序项目。我添加了一个母版页面。然后我添加了两个面板。在每个面板中,我添加了一个ContentPlaceHolder。我为每个ContentPlaceHolder添加了一个ContentPage。
当我使用Vs 2008内部Web服务器运行它时,不会显示任何内容持有者页面。有帮助吗?我怀疑我做的事情从根本上是错误的。
感谢。
以下是代码:
<%@ 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>
答案 0 :(得分:2)
愚蠢的问题:你有这个设置吗?
,您应该有两个<asp:ContentPlaceHolder>
具有单独的ID,例如
<asp:ContentPlaceHolder id="placeHolder1" runat="server" />
和
<asp:ContentPlaceHolder id="placeHolder2" runat="server" />
(基于该母版页),您应该<asp:Content>
引用母版页中定义的适当占位符:
<asp:Content id="content1" ContentPlaceholderID="placeHolder1" runat="server">
....
</asp:Content>
和
<asp:Content id="content2" ContentPlaceholderID="placeHolder2" runat="server">
....
</asp:Content>
答案 1 :(得分:0)
确保您的ContentPlaceHolder和内容代码都有runat="server"
。
答案 2 :(得分:-1)
以下是代码:
<%@ 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>