开发者

Javascript Confirm box redirection in asp.net web application?

开发者 https://www.devze.com 2023-04-03 02:24 出处:网络
Here 开发者_JS百科is my code Type cstype = this.GetType(); ClientScriptManager cs = this.ClientScript;

Here 开发者_JS百科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 ?


The confirm function returns a boolean value indicating whether the user selected OK or Cancel. So all you need to do is to redirect only if this function returns 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";
}
0

精彩评论

暂无评论...
验证码 换一张
取 消