问题描述
亲爱的所有人..
我是编程新手..
我在创建母版页时遇到了一些问题.
我收到错误消息为"
Dear All..
I am new to Programming..
I am facing Some Problem in the Creation Of the master Page.
I am Getting the Error as "
Cannot find ContentPlaceHolder 'HeadContent' in the master page '/MasterPage/Site.master', verify content control's ContentPlaceHolderID attribute in the content page."
请同样帮我.
以下是代码
< pre lang ="xml">& lt;%@ Master Language =& quot; C#& quot; AutoEventWireup =& quot; true& quot; CodeFile =& quot; Site.master.cs& quot; Inherits =&"Site&" %& gt;
<!DOCTYPE html PUBLIC"-//W3C//DTD XHTML 1.0 Transitional//EN&"& quot; http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd& quot;
& lt; html xmlns =&"http://www.w3.org/1999/xhtml&"& gt;
& lt; head runat =& quot;服务器& quot;"
& lt; title& gt;使用母版页& lt;/title& gt;
& lt; asp:ContentPlaceHolder ID =&"head& quot; runat =& quot;服务器& gt;
& lt;/asp:ContentPlaceHolder& gt;
& lt//head& gt;
& lt; body& gt;
& lt; form id =& quot; form1& quot; runat =& quot;服务器& gt;
& lt; div& gt;
& lt; asp:ContentPlaceHolder id =& quot; ContentPlaceHolder1& quot; runat =& quot;服务器& gt;
< asp:Panel ID =&"Panel1& quot; runat =&服务器"宽度=&"100%& amp;". BackColor =&栗色&"& gt;
<表宽度=& quot; 100%& quot; style =&"height:0px&"& gt;
& lt; tr& gt;
& lt; td& gt;
& lt; a href =& quot; MainPage.aspx& quot;& gt;
< asp:图片ID =&图片1&" runat =&服务器" ImageUrl =& quot;〜/Images/mini_logo.gif& quot; /& gt;
& lt;/a& gt;
& lt//td& gt;
< td style =& quot;宽度:90%& quot;< br/> & lt; div style =& quot;文本对齐:居中"& gt;
& lt; h1& gt;
< asp:Label ID =& quot; Label1& quot; runat =&服务器" Style =&"font-weight:700;颜色:#FFFFFF; background-color:#9F0040& quot;
文字=& quot; ZAID QURESHI"& lt;/amp; lt;/asp:Label& gt;
& lt//h1& gt;
& lt//div& gt;
& lt//td& gt;
& lt; td& gt;
& lt; a href =& quot; MainPage.aspx& quot;& gt;
& lt; asp:图片ID =&图片2&" runat =&服务器" ImageUrl =& quot;〜/Images/pw_logo.gif& quot; /& gt;
& lt;/a& gt;
& lt//td& gt;
& lt//tr& gt;
& lt//table& gt;
& lt; table& gt;
& lt; tr& gt;
& lt; td& gt;
& lt; asp:Menu ID =& quot; Menu1& quot; runat =&服务器" BackColor =&#FFFBD6& quot; DynamicHorizontalOffset =&"2&"
Font-Names =& quot; Verdana& quot;字体大小=&"0.8em&". ForeColor =󱬰&" StaticSubMenuIndent =&"10px&"& gt;
& lt; DynamicHoverStyle BackColor =& quot;#990000& quot; ForeColor =&白色". /& gt;
& lt; DynamicMenuItemStyle HorizontalPadding =& quot; 5px& quot; VerticalPadding =&"2px&" /& gt;
& lt; DynamicMenuStyle BackColor =& quot;#FFFBD6& quot; /& gt;
& lt; DynamicSelectedStyle BackColor =& quot;#FFCC66& quot; /& gt;
& lt;物品& gt;
& lt; asp:MenuItem Text =& quot; Home& quot;值=&首页& amp;" NavigateUrl =& quot; MainPage.aspx& quot;& lt;/asp:MenuItem& gt;
& lt;/Items& gt;
& lt; StaticHoverStyle BackColor =󱬰& quot; ForeColor =&白色". /& gt;
& lt; StaticMenuItemStyle HorizontalPadding =& quot; 5px& quot; VerticalPadding =&"2px&" /& gt;
& lt; StaticSelectedStyle BackColor =& quot;#FFCC66& quot; /& gt;
& lt;/asp:Menu& gt;
& lt//td& gt;
& lt; td& gt;
& lt; asp:Menu ID =& quot; Menu2& quot; runat =&服务器" BackColor =&#FFFBD6& quot; DynamicHorizontalOffset =&"2&"
Font-Names =& quot; Verdana& quot;字体大小=&"0.8em&". ForeColor =󱬰&" StaticSubMenuIndent =&"10px&"& gt;
& lt; DynamicHoverStyle BackColor =& quot;#990000& quot; ForeColor =&白色". /& gt;
& lt; DynamicMenuItemStyle HorizontalPadding =& quot; 5px& quot; VerticalPadding =&"2px&" /& gt;
& lt; DynamicMenuStyle BackColor =& quot;#FFFBD6& quot; /& gt;
< DynamicSelectedStyle BackColor =& quot;#FFCC66& quot; /& gt;
& lt;物品& gt;
& lt; asp:MenuItem Text =&关于美国& quot;值=&关于美国" NavigateUrl =" About.aspx& quot;& lt;/asp:MenuItem& gt;
& lt;/Items& gt;
& lt; StaticHoverStyle BackColor =󱬰& quot; ForeColor =&白色". /& gt;
& lt; StaticMenuItemStyle HorizontalPadding =& quot; 5px& quot; VerticalPadding =&"2px&" /& gt;
& lt; StaticSelectedStyle BackColor =& quot;#FFCC66& quot; /& gt;
& lt;/asp:Menu& gt;
& lt//td& gt;
& lt//tr& gt;
& lt//table& gt;
& lt//asp:Panel& gt;
& lt;/asp:ContentPlaceHolder& gt;
& lt//div& gt;
& lt//form& gt;
& lt//body& gt;
& lt;/html& gt;</pre>
请帮我做同样的事情...
谢谢,
plz help me in the same.
The following is the code
<pre lang="xml"><%@ Master Language="C#" AutoEventWireup="true" CodeFile="Site.master.cs" Inherits="Site" %>
<!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>Working With Master Page</title>
<asp:ContentPlaceHolder ID="head" runat="server">
</asp:ContentPlaceHolder>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:ContentPlaceHolder id="ContentPlaceHolder1" runat="server">
<asp:Panel ID="Panel1" runat="server" Width="100%" BackColor="Maroon">
<table width="100%" style="height: 0px">
<tr>
<td>
<a href="MainPage.aspx">
<asp:Image ID="Image1" runat="server" ImageUrl="~/Images/mini_logo.gif" />
</a>
</td>
<td style="width: 90%">
<div style="text-align: center">
<h1>
<asp:Label ID="Label1" runat="server" Style="font-weight: 700; color: #FFFFFF; background-color: #9F0040"
Text="ZAID QURESHI"></asp:Label>
</h1>
</div>
</td>
<td>
<a href="MainPage.aspx">
<asp:Image ID="Image2" runat="server" ImageUrl="~/Images/pw_logo.gif" />
</a>
</td>
</tr>
</table>
<table>
<tr>
<td>
<asp:Menu ID="Menu1" runat="server" BackColor="#FFFBD6" DynamicHorizontalOffset="2"
Font-Names="Verdana" Font-Size="0.8em" ForeColor="#990000" StaticSubMenuIndent="10px">
<DynamicHoverStyle BackColor="#990000" ForeColor="White" />
<DynamicMenuItemStyle HorizontalPadding="5px" VerticalPadding="2px" />
<DynamicMenuStyle BackColor="#FFFBD6" />
<DynamicSelectedStyle BackColor="#FFCC66" />
<Items>
<asp:MenuItem Text="Home" Value="Home" NavigateUrl="MainPage.aspx"></asp:MenuItem>
</Items>
<StaticHoverStyle BackColor="#990000" ForeColor="White" />
<StaticMenuItemStyle HorizontalPadding="5px" VerticalPadding="2px" />
<StaticSelectedStyle BackColor="#FFCC66" />
</asp:Menu>
</td>
<td>
<asp:Menu ID="Menu2" runat="server" BackColor="#FFFBD6" DynamicHorizontalOffset="2"
Font-Names="Verdana" Font-Size="0.8em" ForeColor="#990000" StaticSubMenuIndent="10px">
<DynamicHoverStyle BackColor="#990000" ForeColor="White" />
<DynamicMenuItemStyle HorizontalPadding="5px" VerticalPadding="2px" />
<DynamicMenuStyle BackColor="#FFFBD6" />
<DynamicSelectedStyle BackColor="#FFCC66" />
<Items>
<asp:MenuItem Text="About US" Value="About US" NavigateUrl="About.aspx"></asp:MenuItem>
</Items>
<StaticHoverStyle BackColor="#990000" ForeColor="White" />
<StaticMenuItemStyle HorizontalPadding="5px" VerticalPadding="2px" />
<StaticSelectedStyle BackColor="#FFCC66" />
</asp:Menu>
</td>
</tr>
</table>
</asp:Panel>
</asp:ContentPlaceHolder>
</div>
</form>
</body>
</html></pre>
Plz help me for the same...
Thanks,
推荐答案
<asp:contentplaceholder id="head" runat="server" >
</asp:contentplaceholder><!--Take note of id='head' -->
使用母版页的Web内容页必须使用与母版页文件中指定的占位符ID相同的内容元素.
Web content pages those which use the master page must use content elements which has the same placeholder id specified in Master Page File.
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
<!--ContentPlaceHolderID="head" is important-->
</asp:Content>
在您的情况下,您使用的是ContentPlaceHolderID,而在这样的母版页中未指定.
In your case you are using a ContentPlaceHolderID which is not specified in master page like this.
<asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" runat="server">
</asp:Content> <!-- change ContentPlaceHolderID="HeadContent" to ContentPlaceHolderID="head" -->
这样可以修复错误.
希望对您有所帮助.
This will fix the error.
Hope it helps.
这篇关于在母版页"/MasterPage/Site.master"中找不到ContentPlaceHolder"HeadContent",请在内容页中验证内容控件的ContentPlaceHolderID属性.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!