2010-08-12 61 views
3

我試圖在我的網站中使用母版頁。我創建了一個頁面,然後創建了主頁。然後我添加了標籤MasterPageFile =「〜/ master」。我猜,我需要做一些事來我的主頁,因爲我現在已經開始得到錯誤:ASP.NET MasterPageFile導致錯誤

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

我的主要頁面如下:

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

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

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

我試圖刪除標籤認爲這可能是問題。任何人都可以將我指向正確的方向嗎?

回答

5

您需要將您的body更改爲content板塊。主頁與contentplaceholders一起使用:您的內容頁面需要爲這些佔位符提供內容。 See the msdn page on this topic.

從該鏈接以上報價,您的主頁可能包含以下內容:

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

其內容頁面將通過提供以下

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

注意,我包括主要申報填寫在內容頁面的頂部。

1

繼承母版頁的頁面應該有一個<asp:Content作爲它們的根。這意味着不需要HTML標籤,無文件種類等。