登录成功之后返回上一页面之前怎么能是其弹出消息框,提示登录成功。
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
if (Request.UrlReferrer != null)
ViewState["UrlReferrer"] = Request.UrlReferrer.ToString();
}
}
protected void Button1_Click(object sender, EventArgs e)
{
if (TextBox1.Text == "")
{
showMessage("用户名不能为空!", this);
}
else if (TextBox2.Text == "")
{
showMessage("密码不能为空!", this);
}
else
{
string name = TextBox1.Text.Trim();
string pwd = TextBox2.Text.Trim();
string constr = "server=.;database=Movie;uid=sa;pwd=;";
SqlConnection conn = new SqlConnection(constr);
conn.Open();
string sqlstr = "select * from UserInfo where Name='" + name + "'and Password='" + pwd + "'";
SqlCommand cmd = new SqlCommand(sqlstr, conn);
SqlDataAdapter sda = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
sda.Fill(ds, "aa");
if (ds.Tables["aa"].Rows.Count > 0)
{
showMessage("登录成功!", this);
Session["name"] = name;
Session["ID"] = ds.Tables[0].Rows[0][0].ToString();
Response.Redirect(ViewState["UrlReferrer"].ToString());
}
else
{
showMessage("登录失败!", this);
}
TextBox1.Text = "";
TextBox2.Text = "";
TextBox1.Focus();
}
}