关于如何在.cs页面中写弹出窗口

其语法为:

 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);

        }

    }

你可能感兴趣的:(弹出窗口)