views:

17

answers:

2

I'm trying to use a master page in my website. I created a page and then created the master. I then added the tag MasterPageFile="~/master". I'm guessing that I need to do something to my main page, because I've now started getting the error:

The page contains markup that is not valid when attached to a master page

My main page is as follows:

<%@ Page Language="C#" AutoEventWireup="true"  CodeFile="Default.aspx.cs" Inherits="_Default" MasterPageFile="~/my.master" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;

<html xmlns="http://www.w3.org/1999/xhtml"&gt;
<body>
     <form id="form1" runat="server">
     <div>

     </div>
     </form>
</body>
</html>

I tried deleting the tag thinking that this might be the issue. Can anyone point me in the right direction?

+1  A: 

the pages inhering master page should have a <asp:Content as their root. this means no html tag no doctype etc.

ajay_whiz
+1  A: 

You need to change your body to content sections. The master page works with contentplaceholders: your content pages need to provide the content for these placeholders. See the msdn page on this topic.

Quoted from that link above, your master page could contain the following:

<td><asp:contentplaceholder id="Main" runat="server" /></td>

Which the content page would fill by supplying the following

<% @ Page Language="C#" MasterPageFile="~/Master.master" Title="Content Page 1" %>
<asp:Content ID="Content1" ContentPlaceHolderID="Main" Runat="Server">
    Main content.
</asp:Content>

Note that I included the main declaration at the top of the content page.

Tobiasopdenbrouw