帮看一下哦。。谢谢各位
protected void Button1_Click(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection("server=localhost;Initial Catalog=luntan;Integrated Security=SSPI;uid=;pwd=");
try
{
con.Open();
}
catch (Exception ex)
{
throw ex;
}
string strcom;
strcom = "select count(*) from USERS where USERNAME='" + TextBox1.Text + "'and USERPWD='" + TextBox2.Text + "'";
SqlCommand com = new SqlCommand(strcom, con);
int a=Convert.ToInt32(com.ExecuteScalar());
if (a > 0)
{
Response.Write("<script>alert('恭喜您登录成功!');location='javascript:history.go(-1)'</script>");
Session["UserName"] = this.TextBox1.Text;
Session["UserPwd"] = this.TextBox2.Text;
this.Literal1.Text = Session["UserName"] .ToString()+ " " + "登录成功";
this.TextBox1.Text = "";//填写用户名的textbox
this.TextBox2.Text = "";//填写密码的textbox[/color]
}
else
{
Response.Write("<script>alert('很遗憾,登录失败!');location='javascript:history.go(-1)'</script>");
}
con.Close();
}
登陆以后不能清空用户名和密码啊?这事什么原因啊?我是这样清空的
this.TextBox1.Text = "";//填写用户名的textbox
this.TextBox2.Text = "";//填写密码的textbox
还有this.Literal1.Text = Session["UserName"] .ToString()+ " " + "登录成功"; 这一句也不能显示
原来是可以清空的,因为是一边看书一边试,不知道什么时候他就清空不了了,不知道是不是自己该了什么东西!
------解决方案--------------------
C# code
//把location...去掉
Response.Write("<script>alert('恭喜您登录成功!');'</script>");