简体   繁体   English

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

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

Here is my code 这是我的代码

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

            }

I m trying to implement the confirmbox in my web application which comes up when user hits signout button ...with the options ok and cancel with the above code.with the above code i am able to redirect to the default page when user hits "ok" on the confirmbox.I want to remain on the same page when user hits the "cancel" button on the confirmbox .How do i do it ? 我正在尝试在我的Web应用程序中实现确认框,当用户点击退出按钮时出现该确认框...使用ok选项并使用上述代码取消。使用上述代码,当用户点击“确认”上的“确定”。当用户单击“确认”上的“取消”按钮时,我希望保留在同一页面上。我该怎么做?

The confirm function returns a boolean value indicating whether the user selected OK or Cancel . 确认函数返回一个boolean值,指示用户是选择OK还是Cancel So all you need to do is to redirect only if this function returns true: 因此,您需要做的就是在此函数返回true时重定向

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

Just add a conditional to the redirect. 只需向重定向添加条件。

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