我正在構建登錄表單。如果用戶嘗試使用無效的用戶名/密碼進行3次嘗試登錄,則必須在給定的持續時間內禁用提交按鈕。如何在給定的時間內禁用提交按鈕?
我該怎麼做?
這裏是我現有的代碼:
protected void Button1_Click(object sender, EventArgs e)
{
int count = 0;
string username = TextBox1.Text.Trim();
string password = TextBox2.Text.Trim();
String connString = ConfigurationManager.ConnectionStrings["Myconnection"].ToString();
SqlConnection conn = new SqlConnection(connString);
SqlCommand cmd = new SqlCommand("Login", conn);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@username", username);
cmd.Parameters.AddWithValue("@password", password);
conn.Open();
SqlDataReader read = cmd.ExecuteReader();
read.Read();
if (read.HasRows)
{
Session["LoggedIn"] = "correct";
Response.Redirect("WebForm2.aspx", false);
}
else
{
Label1.Visible = true;
Label1.Text = "Wrong user/password";
conn.Close();
}
if (System.Convert.ToInt32(ViewState["Tries"]) == 2)
{
Label1.Text = "Exceeded 3 times Attempts.Please Login after some time";
TextBox1.Enabled = false;
TextBox2.Enabled = false;
Button1.Enabled = false; // Button1 is the submit button
}
else
{
// Otherwise, increment number of tries.
ViewState["Tries"] = System.Convert.ToInt32(ViewState["Tries"]) + 1;
if (System.Convert.ToInt32(ViewState["Tries"]) == 2)
Label1.Text = "Exceeded 3 times Attempts.Please Login after some time";
}
}
那麼什麼是不工作? – gideon 2012-03-01 07:13:47
你有我的答案... – 2012-03-01 07:26:46