Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Javascript Alert before redirecting in ASP.NET

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");
like image 390
Rohit Chaudhari Avatar asked Aug 31 '12 06:08

Rohit Chaudhari


People also ask

How to redirect a JavaScript alert message box?

message – The message to be displayed in the JavaScript Alert Message Box. url – URL of the page or website when the user will be redirected once he clicks OK button. script – The JavaScript code that will display the Alert Message Box and then redirect.

How to redirect the alert message box to aspsnippets home page?

script – The JavaScript code that will display the Alert Message Box and then redirect. string message = "You will now be redirected to ASPSnippets Home Page."; Dim message As String = "You will now be redirected to ASPSnippets Home Page."

How to redirect a text message to another page?

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

How to add an alert message to a popup page?

2.put a iframe with 0 width and height on your current page. 3.Set the scr of the your iframe to popup.aspx on the event you are working on. 4.create a javascript function for alert message on your popup.aspx page and call it on page's onload.


2 Answers

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);
like image 151
Vishal Suthar Avatar answered Sep 23 '22 10:09

Vishal Suthar


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";
like image 40
Aristos Avatar answered Sep 21 '22 10:09

Aristos