1

我有一个带有母版页的登录表单代码,但是当我在浏览器上运行它时出现错误。我无法理解错误,我该如何删除它?还附上了错误图片。请问有人可以帮助我吗?

我的代码是:

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

<%@ MasterType VirtualPath="~/MasterPage.master" %>
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title>Login Form</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<table align="center">

<b>Login Form</b>

<tr>
<td>
Username:
</td>
<td>
<asp:TextBox ID="txtUserName" runat="server"/>
<asp:RequiredFieldValidator ID="rfvUser" ErrorMessage="Please enter Username" ControlToValidate="txtUserName" runat="server" />
</td>
</tr>
<tr>
<td>
Password:
</td>
<td>
<asp:TextBox ID="txtPWD" runat="server" TextMode="Password"/>
<asp:RequiredFieldValidator ID="rfvPWD" runat="server" ControlToValidate="txtPWD" ErrorMessage="Please enter Password"/>
</td>
</tr>
<tr>
<td>
</td>
<td>
<asp:Button ID="btnSubmit" runat="server" Text="Submit" onclick="btnSubmit_Click" />
</td>
</tr>
</table>
</div>
</form>
</body>
</html>
</asp:Content>

母版页代码是:

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

<!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 id="Head1" runat="server">
    <title>Untitled Page</title>
</head>
<body style="background-color:Teal;">

    <form id="form1" runat="server">
    <div align="center">
        <h1>My Test WebSite</h1>
        <div align = "left">
            <asp:Label ID="lblpageName" runat="server"></asp:Label>

        <asp:Menu ID="Menu1" runat="server" BackColor="#B5C7DE" DynamicHorizontalOffset="3"
            Font-Names="Verdana" Font-Size="1em" ForeColor="#284E98" Orientation="Horizontal"
            StaticSubMenuIndent="20px" Height="25px" Width="550px">
            <StaticMenuItemStyle HorizontalPadding="5px" VerticalPadding="3px" />
            <DynamicHoverStyle BackColor="#284E98" ForeColor="White" />
            <DynamicMenuStyle BackColor="#B5C7DE" />
            <StaticSelectedStyle BackColor="#507CD1" />
            <DynamicSelectedStyle BackColor="#507CD1" />
            <DynamicMenuItemStyle HorizontalPadding="5px" VerticalPadding="2px" />
            <Items>
                <asp:MenuItem Text="HOME" Value="HOME" NavigateUrl="~/Default.aspx"></asp:MenuItem>
                <asp:MenuItem Text="ABOUT" Value="ABOUT" NavigateUrl="~/about.aspx"></asp:MenuItem>
                <asp:MenuItem Text="CONTACT" Value="CONTACT" NavigateUrl="~/contact.aspx"></asp:MenuItem>
                <asp:MenuItem NavigateUrl="~/Change.aspx" Text="CHANGE" Value="CHANGE"></asp:MenuItem>
                <asp:MenuItem Text="LOGIN" Value="Login" NavigateUrl="~/Login.aspx"></asp:MenuItem>
            </Items>
            <StaticHoverStyle BackColor="#284E98" ForeColor="White" />
        </asp:Menu>

        </div>
        <!-- Here we have content place holder where all content pages will render their controls   -->
        <hr />
        <asp:contentplaceholder id="ContentPlaceHolder1" runat="server">
        </asp:contentplaceholder>

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

错误图片是: 在此处输入图像描述

4

2 回答 2

1

runat="server"从您的内容页面中删除 。

保持它为<head>.....</head>

由于在您的母版页中有带有runat=server(might have) 的 head 标签,您应该将其从内容页面中删除。

编辑:

删除以下:

<head id="Head1" runat="server">
<title>Login Form</title>
</head>
于 2013-07-18T08:14:56.363 回答
1

您使用的 aMasterPage其中也有一个Head标签,这就是您收到此错误的原因。因此,将其从您的内容页面中删除。

<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
<div>
<table align="center">
<b>Login Form</b>
....
于 2013-07-18T08:15:47.920 回答