繁体   English   中英

javascript在asp.net Web应用程序中确认框重定向?

[英]Javascript Confirm box redirection in asp.net web application?

这是我的代码

 Type cstype = this.GetType();
            ClientScriptManager cs = this.ClientScript;
            if (!cs.IsStartupScriptRegistered(cstype, "Script"))
            {
               String csScriptText = "confirm('Are you sure you want to leave the page');document.location='Default.aspx'";
                cs.RegisterStartupScript(cstype, "TestScript", csScriptText, true);

            }

我正在尝试在我的Web应用程序中实现确认框,当用户点击退出按钮时出现该确认框...使用ok选项并使用上述代码取消。使用上述代码,当用户点击“确认”上的“确定”。当用户单击“确认”上的“取消”按钮时,我希望保留在同一页面上。我该怎么做?

确认函数返回一个boolean值,指示用户是选择OK还是Cancel 因此,您需要做的就是在此函数返回true时重定向

String csScriptText = "if (confirm('Are you sure you want to leave the page')){document.location='Default.aspx';}";

只需向重定向添加条件。

Type cstype = this.GetType();
            ClientScriptManager cs = this.ClientScript;
            if (!cs.IsStartupScriptRegistered(cstype, "Script"))
            {
               String csScriptText = "if(confirm('Are you sure you want to leave the page')) {document.location='Default.aspx'}";
                cs.RegisterStartupScript(cstype, "TestScript", csScriptText, true);

            }
if (confirm('some text here')) {
    window.location = "Default.aspx";
}

暂无
暂无

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

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