I’m new in ASP.Net and I want to creat a very simple form which bind to a master page but no success. this is my Master Page code:
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<asp:ContentPlaceHolder ID="HeadContent" runat="server" />
</head>
<body>
<form runat=server>
<asp:ContentPlaceHolder ID="MainContent" runat="server">
<body>
<table width=100% border=1 style="background:black" >
<tr>
<td width=20%></td>
<td width=80%><asp:Label ID="Label1" runat="server" Text="Label"></asp:Label></td>
<td width=20%></td>
</tr>
</table>
</body>
</asp:ContentPlaceHolder>
</form>
</body>
</html>
and code of my page is:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<asp:Content ContentPlaceHolderID=HeadContent runat=server>
</asp:Content>
<asp:Content ID="MainContent" runat=server ContentPlaceHolderID=MainContent >
</asp:Content>
but hte table in the Master Page doesn’t appear in the page.Would you please help me to solve this problem?
For starters,
is entirely wrong.
The
DOCTYPEshould be listed in the master. Secondly:Would more closely match your intent. But one flaw in your style, as it were, and this is strictly a style thing:
Notice how I put
runat="server"at the end, on both tags? Always put that at the end, it’ll make it easier to make sure you’ve put it in the right place. Alternately, always put it right beforeIDEdit:
Where you have this in the master page, the contents of the
ContentPlaceHolderwon’t be shown when a child page implements this section. You’ll need to move those outside of the master pageContentPlaceHolderdeclaration. This concept is very "either or" and there is no room to have an alternate opinion. It was written this way on purpose.Perhaps you want: