ASP.NET(脚本或asp:content之外不支持内容)

时间:2018-02-21 20:42:44

标签: html css asp.net html5 visual-studio

我在嵌套母版页上创建了一个导航栏,允许在从中创建的每个Web表单页面上都有一个导航栏。我一直在< html>如标题中所述,在页面顶部标记。我所拥有的页面的代码如下。

NestedMasterPage1.Master:

 <%@ Master Language="C#" MasterPageFile="~/Site.Master"
 AutoEventWireup="true" CodeBehind="NestedMasterPage1.master.cs"
 Inherits="TGASAttempt.NestedMasterPage1" %>
     <!DOCTYPE html> <html> <head> <link href="StyleSheet.css" rel="stylesheet" /> <link
 href="https://fonts.googleapis.com/css?family=Work+Sans"
 rel="stylesheet">

     <title>Navbar</title> </head> <body>
     <header>

         <div class="container">
             <img src="TGASlogo.png" alt="logo" class="logo">

             <nav>
                 <ul>
                     <li><a href="~/">Home Page</a></li>
                     <li><a href="~/">About</a></li>
                     <li><a href="~/">Tab1</a></li>
                     <li><a href="~/">Tab2</a></li>
                     <li><a href="~/">Tab3</a></li>
                     <li><a href="~/">Tab4</a></li>
                     <li><a href="~/">Tab5</a></li>
                     <li><a href="~/">Tab6</a></li>
                     <li><a href="~/">Tab7</a></li>
                     <li><a href="~/">Tab8</a></li>
                 </ul>
             </nav>

         </div>
     </header>
     <div>
             <asp:ContentPlaceHolder ID="ContentPlaceHolder1" runat="server">
             </asp:ContentPlaceHolder>
         </div> </body> </html>

HomePage.aspx

 <%@ Page Language="C#" MasterPageFile="~/NestedMasterPage1.master"
 CodeBehind="Home Page.aspx.cs" Inherits="TGASAttempt.WebForm1"  %>


 <asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
 </asp:Content>

 <asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1"
 runat="server">


      </asp:Content>

的Site.Master

 <%@ Master Language="C#" AutoEventWireup="true"
 CodeBehind="Site.master.cs" Inherits="TGASAttempt.Site" %>

 <!DOCTYPE html>

 <html> <head runat="server">
     <title></title>
     <asp:ContentPlaceHolder ID="head" runat="server">
     </asp:ContentPlaceHolder> </head> <body>
     <form id="form1" runat="server">
         <div>
             <asp:ContentPlaceHolder ID="ContentPlaceHolder1" runat="server">
             </asp:ContentPlaceHolder>
         </div>
     </form> </body> </html>

1 个答案:

答案 0 :(得分:0)

由于嵌套母版页嵌套在Site.Master中,因此无需重复所有html,head等标记。主Master页面的重点是它已经为你完成了所有这些工作。同样重复尝试在另一个HTML文档中声明一个HTML文档,这不是一件好事。

嵌套页面中的内容也应该在<asp:Content>块中声明,该块对应于Site.Master中声明的ContentPlaceHolder块之一 - 这就是错误告诉你的。

例如:

<%@ Master Language="C#" MasterPageFile="~/Site.Master"
 AutoEventWireup="true" CodeBehind="NestedMasterPage1.master.cs"
 Inherits="TGASAttempt.NestedMasterPage1" %>

<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
  <link href="StyleSheet.css" rel="stylesheet" /> <link
 href="https://fonts.googleapis.com/css?family=Work+Sans"
 rel="stylesheet">

  <title>Navbar</title>
  <asp:ContentPlaceHolder ID="head" runat="server">
  </asp:ContentPlaceHolder>
 </asp:Content>

<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1"
 runat="server">

  <header>

     <div class="container">
         <img src="TGASlogo.png" alt="logo" class="logo">

         <nav>
             <ul>
                 <li><a href="~/">Home Page</a></li>
                 <li><a href="~/">About</a></li>
                 <li><a href="~/">Tab1</a></li>
                 <li><a href="~/">Tab2</a></li>
                 <li><a href="~/">Tab3</a></li>
                 <li><a href="~/">Tab4</a></li>
                 <li><a href="~/">Tab5</a></li>
                 <li><a href="~/">Tab6</a></li>
                 <li><a href="~/">Tab7</a></li>
                 <li><a href="~/">Tab8</a></li>
             </ul>
         </nav>

     </div>
  </header>
  <div>
         <asp:ContentPlaceHolder ID="ContentPlaceHolder1" runat="server">
         </asp:ContentPlaceHolder>
     </div>
</asp:Content>