其语法为:

 ClientScript.RegisterStartupScript(this.GetType(), "", "alert('用户名或密码错误!');", true);

 

下面给出一个登录窗口点登陆后的单击按钮后台代码,用户名和密码都正确,转向admin.aspx 页面,否则错误弹出窗口

 protected void LoginButton_Click1(object sender, EventArgs e)
    {
        if (UserName.Text.Trim().Equals("mr") && Password.Text.Trim().Equals("123"))
        {
            Session["username"] = UserName.Text.Trim();
            if (RememberMe.Checked)
            {
                if (Request.Cookies["username"] == null)
                {
                    Response.Cookies["username"].Expires = DateTime.Now.AddDays(30);
                    Response.Cookies["userpwd"].Expires = DateTime.Now.AddDays(30);
                    Response.Cookies["username"].Value = UserName.Text.Trim();
                    Response.Cookies["userpwd"].Value = Password.Text.Trim();
                }
            }
            Response.Redirect("admin.aspx");
        }
        else
        {
            ClientScript.RegisterStartupScript(this.GetType(), "", "alert('用户名或密码错误!');", true);
        }
    }

相关文章:

  • 2021-12-10
  • 2022-12-23
  • 2022-12-23
  • 2021-06-13
  • 2021-09-07
  • 2022-12-23
  • 2021-11-16
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-05-19
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案