2010-11-16 66 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