aspx文件中的Runat错误

时间:2013-07-18 08:11:19

标签: c# asp.net login runtime-error

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

我的代码是:

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

错误图片是: enter image description here

2 个答案:

答案 0 :(得分:1)

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

将其保留为<head>.....</head>

由于您的母版页中包含runat=server(可能有)的标题,因此您应将其从内容页面中删除。

修改

删除以下内容:

<head id="Head1" runat="server">
<title>Login Form</title>
</head>

答案 1 :(得分:1)

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

<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
<div>
<table align="center">
<b>Login Form</b>
....