ASP.NET页面冻结

时间:2012-07-03 05:01:11

标签: c# asp.net

所以,我在C#中创建了一个ASP.NET页面。我有一个非常简单的表单,上面有2个文本框和3个按钮。当我单击“提交”按钮时,它会调用SQL Server数据库来检索某些信息。检索数据后,我有一个if语句来检查其中一个加载的值。问题是单击按钮后页面似乎冻结,我无法再次单击它。我仍然可以在文本框中输入数据,但按钮不会显示为LinkBut​​ton,鼠标图标不会更改或任何内容。 ASPX.CS页面的代码如下:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using CharacterSheet.BLL;
using CharacterSheet.Data;

public partial class Login : System.Web.UI.Page
{

    protected void ClearButton_Click(object sender, EventArgs e)
    {
        UserBox.Text = "";
        PassBox.Text = "";
    }

    protected void SubmitButton_Click(object sender, EventArgs e)
    {
        PlayerController pc = new PlayerController();
        Player player;

        if (UserBox.Text.Contains('@') && UserBox.Text.Contains(".c"))
            player = pc.GetByEmail(UserBox.Text);
        else
            player = pc.GetByUser(UserBox.Text);


        if (player != null)
        {
            if (!player.Flagged)
            {
                if (PassBox.Text != player.Password)
                {
                    ErrorLabel.Text = "Password does not match our records. Please retype carefully...";

                    player.LoginAttempts++;

                    if (player.LoginAttempts >= 3)
                        player.Flagged = true;

                    pc.Update(player);
                }
                else
                    Response.Redirect(SiteData.LoginMainPage);
            }
            else
                ErrorLabel.Text = "Your account has been flagged. Please e-mail our support team.";
        }
        else
            ErrorLabel.Text = "Unable to find user. Please retype carefully...";
    }
}

ASP标记页面的代码:

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

<asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" Runat="Server">
    <style type="text/css">
        .leftColumn
        {
            text-align: right;
        }
        .style1
        {
            width: 30%;
            text-align: right;
            height: 47px;
        }
        .style2
        {
            width: 70%;
            text-align: right;
            height: 47px;
        }
    </style>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" Runat="Server">
    <table>
        <tr>
            <td class="leftColumn">
                <asp:Label ID="Label1" runat="server" CssClass="FormText" 
                    Text="Username or Email"></asp:Label>
            </td>
            <td>
                <asp:TextBox ID="UserBox" runat="server" ToolTip="Enter your username here"></asp:TextBox>
                <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" 
                    ControlToValidate="UserBox" ErrorMessage="Username or Email is required" 
                    ForeColor="Red">*</asp:RequiredFieldValidator>
            </td>
        </tr>
        <tr>
            <td class="leftColumn">
                <asp:Label ID="Label2" runat="server" CssClass="FormText" Text="Password"></asp:Label>
            </td>
            <td>
                <asp:TextBox ID="PassBox" runat="server" TextMode="Password" 
                    ToolTip="Enter your password here" TabIndex="1"></asp:TextBox>
                <asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" 
                    ErrorMessage="Password is required" ForeColor="Red" 
                    ControlToValidate="PassBox">*</asp:RequiredFieldValidator>
            </td>
        </tr>
        <tr>
            <td class="style1"></td>
            <td class="style2">
                <asp:ValidationSummary ID="ValidationSummary" runat="server" 
                    CssClass="ValidationSumary" ForeColor="Red" Height="43px" 
                    style="text-align: left" Width="335px" DisplayMode="List" />
                <asp:LinkButton ID="SubmitButton" runat="server" CssClass="FormButton" 
                    TabIndex="2" onclick="SubmitButton_Click" PostBackUrl="~/Login.aspx">Submit</asp:LinkButton>
                <asp:LinkButton ID="ClearButton" runat="server" CausesValidation="False" 
                    CssClass="FormButton" TabIndex="3" onclick="ClearButton_Click">Clear</asp:LinkButton>
                <asp:LinkButton ID="NewAcctButton" runat="server" CausesValidation="False" 
                    CssClass="FormButton" TabIndex="4">Create Account</asp:LinkButton>
                <br />
                <asp:Label ID="ErrorLabel" runat="server" ForeColor="Red" 
                    CssClass="FormErrorLabel"></asp:Label>
            </td>
        </tr>
    </table>
</asp:Content>

感谢任何可以提供帮助的人! : - )

编辑:经过进一步调查(按顺序注释掉代码行),我发现当我更新“ErrorLabel.Text”时会出现问题。如果我不这样做,那么它的功能就好......这让我很困惑......

2 个答案:

答案 0 :(得分:1)

如果aspx页面中出现任何不需要的代码或运行时错误,则页面将冻结。为避免再次分析您的代码并删除它将运行的不需要的东西。

答案 1 :(得分:0)

在标签的属性中随机点击按钮后,我发现当我没有将CSS类附加到标签时它会停止...我不明白为什么,但它解决了问题。