3

asp.net にマスターページを追加しようとしていますが、ページにマスターページに添付したときに無効なマークアップが含まれているというエラーが表示されます。ここに私のマスターページファイルがあります:

<%@ Master Language="C#" AutoEventWireup="true" CodeFile="MasterPage.master.cs" 
Inherits="Pages_AdminMaster" %>

<!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></title>
<asp:ContentPlaceHolder id="head" runat="server">
</asp:ContentPlaceHolder>
</head>
<body>
<form id="form1" runat="server">
<div style="text-align: right">
    <asp:ContentPlaceHolder id="ContentPlaceHolder1" runat="server">

        <asp:LinkButton ID="LinkButton1" runat="server" onclick="LinkButton1_Click">Log  Out</asp:LinkButton>

    </asp:ContentPlaceHolder>
</div>
</form>

そして、これが私がそのマスターページを適用するWebフォームです:

<%@ Page Language="C#" MasterPageFile="~/Pages/MasterPage.master" 
AutoEventWireup="true" CodeFile="Admin.aspx.cs" Inherits="Pages_Admin" %>

<!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></title>
<style type="text/css">
    .style1
    {
        text-decoration: underline;
        color: #0000FF;
    }
    .style2
    {
        font-family: 15;
        font-size: 12pt;
        color: #0000FF;
    }
</style>
</head>
<body>
<form id="form1" runat="server">
<div class="style2" style="text-align: right">

</div>
</form>
<p class="style1">
    <a href="CreateCourse.aspx">Create a new course</a></p>
<p class="style1">
    <a href="ModifyCourse.aspx">Modify a course</a></p>
<p class="style1">
    <a href="CreateAccount.aspx">Create a new account</a></p>
<p class="style1">
    <a href="DeleteAccount.aspx">Delete an account</a></p>
<p class="style1">
    <a href="DisableAccount.aspx">Disable an Account</a></p>
<p class="style1">
    <a href="DropStudent.aspx">Drop a Student from a course</a></p>
<p class="style1">
    <a href="EnrollStudent.aspx">Enroll a student to a course</a></p>
<p class="style1">
    <a href="GetStudentInfo.aspx">Get Student info</a></p>
<p class="style1">
    <a href="GetInstructorInfo.aspx">Get Instructor info</a></p>
</body>
</html>

そして、ブラウザのエラーは次のとおりです。

Server Error in '/Bannerweb' Application.

Content controls have to be top-level controls in a content page or a nested master 
page that references a master page.

Description: An unhandled exception occurred during the execution of the current web 
request. Please review the stack trace for more information about the error and where   
it 
originated in the code. 

Exception Details: System.Web.HttpException: Content controls have to be top-level 
controls in a content page or a nested master page that references a master page.

Source Error: 

An unhandled exception was generated during the execution of the current web request. 
Information regarding the origin and location of the exception can be identified using   
the 
exception stack trace below.

Stack Trace: 


[HttpException (0x80004005): Content controls have to be top-level controls in a 
content page or a nested master page that references a master page.]
   System.Web.UI.MasterPage.CreateMaster(TemplateControl owner, HttpContext context, 
VirtualPath masterPageFile, IDictionary contentTemplateCollection) +8968123
   System.Web.UI.Page.get_Master() +54
   System.Web.UI.Page.ApplyMasterPage() +15
   System.Web.UI.Page.PerformPreInit() +45
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean    
includeStagesAfterAsyncPoint) +328

どちらのページも Pages という名前のフォルダーにあります。誰でもこれで私を助けることができますか?ありがとう。

4

3 に答える 3

2

マスター ページを使用する Web フォームでは、マスター ページ<asp:Content ContentPlaceholderID="ContentPlaceHolder1" runat="server"></asp:Content>内の特定のページに表示されるコンテンツをマップするコンテンツを配置する必要があります。

<asp:ContentPlaceHolder />MSDN には、マスター ページとhttp://msdn.microsoft.com/en-us/library/wtxbf3hh(v=vs.100).aspx<asp:Content />で使用する方法に関する詳細情報があります。

于 2013-05-14T15:57:01.220 に答える
2

ビジュアルスタジオで「新しいアイテムを追加..」するときは、「Webフォーム」を選択し、ウィンドウの右下、入力する「名前」ボックスの右側にある「」というボックスをオンにする必要があります。マスターページを選択します。」

これを行うと、[追加] をクリックした後に別のダイアログが表示され、新しい Web フォームで使用するマスター ページを選択できます。

新しい Web フォームには<Content>、通常は Head と Content のタグがあります。あなたのマスターページに応じて。<doctype>Web フォームには、通常のタグや<head>タグなどがすべて含まれているわけではありません。

現在のページをバラバラにして正しいスキーマを取得しようとするのではなく、新しいページを開始して、必要なコードを取り込むだけです。

于 2013-05-14T16:06:09.367 に答える