Reputation: 950
So, I'm making an ASP.NET page in C#. I have a very simple form with 2 textboxes and 3 buttons on it. When I click a button for 'submit' it makes a call to an SQL Server database to retrieve some info. Once the data's retrieved, I have an if statement to check one of the loaded values. The problem is that the page seems to freeze after the button is clicked, and I can't click it again. I can still enter data in the textboxes, but the button doesn't show up as a LinkButton, the mouse icon doesn't change or anything. The code for the ASPX.CS page is below:
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...";
}
}
And the code for the ASP markup page:
<%@ 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>
Thanks to anyone who can help with this! :-)
EDIT: Upon further investigation (commenting out lines of code sequentially), I find that the problem arises when I update "ErrorLabel.Text". If I don't do that, then it functions just fine...this is confusing me a lot now...
Upvotes: 0
Views: 3220
Reputation: 11
If there is any unwanted code in aspx page or runtime error came then the page will freeze.To avoid this analyze your code once again and remove unwanted things it will run.
Upvotes: 1
Reputation: 950
After randomly clicking buttons in the properties of the label, I find it stops breaking when I don't attach a CSS class to the label...I have no idea why, but it fixed the problem.
Upvotes: 0