2010-11-16 95 views
0

这是一个嵌套母版页的在我的项目代码:内容Web窗体不允许添加内容

<%@ 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> 

我有以下疑问:

  1. 第一ContentPlaceHolderContentPlaceHolderID="head",它是什么对于?当我将这个嵌套母版页添加到我的项目中时,两个ContentPlaceHolder都自动添加。
  2. 在第二个ContentPlaceHolderContentPlaceHolderID="ContentPlaceHolder1",我加了两个div s。一种是在左边显示一个侧栏,另一个是我要显示表单的位置。问题是,当我添加了一个新的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秒。即使我尝试添加一个,它会给出错误:

The page has one or more <asp:Content> controls that do not correspond with <asp:ContentPlaceHolder> controls in the Master page.

如何纠正此错误?

回答

1

您需要将ContentPlaceHolders添加到Content元素中的嵌套MasterPage。例如

母版1:

<asp:ContentPlaceHolder ID="ContentPlaceHolder1" runat="server"> 

</asp:ContentPlaceHolder> 

嵌套母版:

<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> 
+0

这意味着上面显示的ContentPlaceHolderID对应于嵌套主页面。 – RKh 2010-11-16 09:16:36

+0

@RPK - yes cphCmsDiv对应于嵌套masterpage中ContentPlaceHolder的ID。编辑我的答案以显示更完整的示例 – 2010-11-16 09:21:11