Javascript Alert before redirecting in ASP.NET
31,700
Solution 1
Display the alert with javascript and then do the redirect with the same:
ScriptManager.RegisterStartupScript(this,this.GetType(),"redirect",
"alert('Time OutAlert'); window.location='" +
Request.ApplicationPath + "Nextpage.aspx';",true);
Solution 2
You can not do that, the way you try because the message is running on the client side, but you make the redirect on code behind before the page loading to show the message.
The way to do that is to call right after the message a client side redirect as:
window.location = "NextPage.asps";
![Rohit Chaudhari](https://i.stack.imgur.com/uUg2i.jpg?s=256&g=1)
Author by
Rohit Chaudhari
Hi, I am Computer Engineer, and Working as a Lead Engineer, Business Intelligence.
Updated on February 11, 2020Comments
-
Rohit Chaudhari over 4 years
I am using following code to display message while updating in update panel
string jv = "alert('Time OutAlert');"; ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "msg", jv, true);
It works fine.
But when I use Redirect after it it loads the page without displaying the message. I want user to see the message and after clicking on "ok" it should redirect.
string jv = "alert('Time OutAlert');"; ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "msg", jv, true); Response.Redirect("~/Nextpage.aspx");
-
Rohit Chaudhari almost 12 yearsHow could I add this to the builtin function?
-
Enrico almost 7 yearsThis solution also works when using routing names instead of full page names.