繁体   English   中英

警报框消失,而无需单击asp.net中的“确定”按钮

[英]alert box disappear without clicking on ok button in asp.net

我要在其中显示警报框,然后将其重定向到asp.net中的其他页面

我的代码是

 var s = Convert.ToInt32(Session["id"].ToString());

        var q = (from p in db.students

            where p.userid == s
            select p.sid).SingleOrDefault();


        if (q == 0)
        {

            this.Page.ClientScript.RegisterStartupScript(this.GetType(), "alert", "reg();", true);


        }

这是我的reg()函数

function reg() {
             var con = alert('Please Register Your Self Fisrt ..!! Thank you');

             window.location = "reg.aspx";

         }

我的代码运行正常,但是警报框在几秒钟后消失,而没有单击它,因为该用户无法阅读警报消息
我想将其重定向到reg.aspx,但是在警告框上单击“确定” ..请帮助

触发确认框而不是警报将完成您要实现的目标。 您可以选择有条件或无条件重定向

function reg(){
    var con=confirm("You need to register first before proceeding. Redirect to Registration Page");

    if(con==true){
      window.location = "reg.aspx";
      }
   else{
        //if redirect unconditionally
        window.location = "reg.aspx";
    }
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM