2

我有一个这样开头的 aspx 页面:

<%@ Page Language="C#" MasterPageFile="~/Main_MP_Teacher.master" AutoEventWireup="true" CodeFile="default.aspx.cs"
    Inherits="Teacher_default" Title="Teacher Page" %>

我也想在此页面中包含 html,但是当我放入第一行时

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/strict.dtd">

我得到一个解析错误。我究竟做错了什么?

4

1 回答 1

7

The parser error is probably because you're putting something other than <asp:ContentPlaceHolder> in the root of your ASPX page.

If you're using a MasterPageFile then the <!DOCTYPE should be at the start of the MasterPage.

This is unless you have a <asp:ContentPlaceHolder> right at the start of the MasterPage, which you can put the <!DOCTYPE into it.

MORE INFORMATION

The <!DOCTYPE should always be the very first thing in the HTML file, so normally your MasterPage would look something like this...

<%@ Master Language="VB" CodeBehind="MyMaster.master.vb" Inherits="dev.MyMaster" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  "http://www.w3.org/TR/xhtml1/DTD/strict.dtd">
<html>
  <head>
    <asp:ContentPlaceHolder runat="server" id="myHeader"/>
  </head>
  <body>
    <form id="form1" runat="server">
      <asp:ContentPlaceHolder runat="server" id="myBody"/>
    </form>
  </body>
</html>

If for some reason you wanted to have a page specified doc type, then you could add a new placeholder at the start, with a default value...

<%@ Master Language="VB" CodeBehind="MyMaster.master.vb" Inherits="dev.MyMaster" %>
<asp:ContentPlaceHolder runat="server" id="myDocType">
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  "http://www.w3.org/TR/xhtml1/DTD/strict.dtd">
</asp:ContentPlaceHolder>
<html>
  ...
</html>

And then in the page you want to override put the following (by NOT overriding, the original will be output instead)...

<%@ Page Language="vb" MasterPageFile="MyMaster.master" Codebehind="MyPage.aspx.vb"
  Inherits="dev.MyPage" Title="My Page" %>
<asp:Content runat="server" ContentPlaceHolderId="myDocType">
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
   "http://www.w3.org/TR/html4/loose.dtd">
</asp:Content>
...
于 2012-07-03T11:42:22.870 回答