简体   繁体   中英

Confirm Box is not working while redirecting to other page in ASP.NET

I am implementing one page where user changes his password. Once he successfully changes his password I want to show a confirm box to user that Your password is successfully changed and You will be redirected to Login Page. So once User selects OK, he will be redirected to Login Page. Here in my case I after changing password successfully, I am not get confirm box, but it is simply redirecting to login page. I want to show confirm box to the User. This is my Code.

 ScriptManager.RegisterStartupScript (this, typeof(string), "NavigateToLoginPage", String.Format("NavigateToLoginPage();"), true);
Session.RemoveAll();
Session.Clear();
Response.Redirect("LoginPage.aspx", false);
Context.ApplicationInstance.CompleteRequest();

this is my javascript code

function NavigateToLoginPage()
{

var message = confirm("Password is changed successfully, You will be redirected to Login Page. Please confirm");

if(message == true)
{

return true;
}
else
{
return false;
}
}

Please suggest me how can I achieve the desired functionality.

You need Remove Response.Redirect("LoginPage.aspx", false);

And in your Javascript Write Redirect

function NavigateToLoginPage()
    {

    var message = confirm("Password is changed successfully, You will be redirected to Login Page. Please confirm");

     if(message == true)
     {
        document.location.href='LoginPage.aspx'
     }
     else
     {
     return false;
     }
    }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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