这是我项目中嵌套母版页的代码:
<%@ Master Language="C#" MasterPageFile="~/Presentation_Layer/Pages/home.Master" AutoEventWireup="true" CodeBehind="cmsNestedMasterPage.master.cs" Inherits="livetest.Presentation_Layer.Pages.cmsNestedMasterPage" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
<div id="divMenuSideBarLeft" class="MainSideBar1Div" style="top: 2px"
title="LiveTest CMS Menu">
</div>
<div id="divCmsContent" class="MainContentDiv" title="divCmsContent"
style="background-color: ButtonFace; width: 791px; left: 203px; position:relative; top: -602px;">
</div>
</asp:Content>
我有以下问题:
ContentPlaceHolder
ContentPlaceHolderID="head"
,它的用途是什么?当我将这个嵌套的母版页添加到我的项目中时,ContentPlaceHolder
都被自动添加。ContentPlaceHolder
的第二个ContentPlaceHolderID="ContentPlaceHolder1"
中,我添加了两个div
。一个是在左边显示一个侧栏,另一个是我要在哪里显示入场表格。问题是,当我添加一个新的Web内容表单并将其链接到该母版页时,它只有一个预先编写的行:<%@ Page Title="" Language="C#"
MasterPageFile="~/Presentation_Layer/Pages/cmsNestedMasterPage.master"
AutoEventWireup="true" CodeBehind="BookEntry.aspx.cs"
Inherits="livetest.Presentation_Layer.Pages.CMS.BookEntry" %>
代码未显示任何ContentPlaceHolder
个。即使我尝试添加一个,也会出错:
该网页包含一个或多个
<asp:Content>
控件,与主页面中的<asp:ContentPlaceHolder>
控件不对应。
如何纠正此错误?
答案 0 :(得分:1)
您需要将ContentPlaceHolders
添加到MasterPage
元素内的嵌套Content
。例如
MasterPage 1:
<asp:ContentPlaceHolder ID="ContentPlaceHolder1" runat="server">
</asp:ContentPlaceHolder>
嵌套MasterPage:
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
<div id="divMenuSideBarLeft" class="MainSideBar1Div" style="top: 2px" title="LiveTest CMS Menu">
</div>
<div id="divCmsContent" class="MainContentDiv" title="divCmsContent" style="background-color: ButtonFace; width: 791px; left: 203px; position:relative; top: -602px;">
<-- Content on page goes inside this ContentPlaceHolder -->
<asp:ContentPlaceHolder ID="cphCmsDiv" runat="server">
</asp:ContentPlaceHolder>
</div>
</asp:Content>
然后将相应的Content
项添加到页面中(它们将自动添加到新页面中):
<asp:Content ID="Content3" ContentPlaceHolderID="cphCmsDiv" runat="server">
</asp:Content>