How to Redirect a page after clicking OK of javascript alert box

Sometimes you need to redirect the user to another page after he clicks on 'OK' button in the javascript alert box.

Just type your complete script and assign it to a string variable.
register it with RegisterStartupScript as follows.

Look at this example :

C# code behind:
string strScript = "<script>";
strScript += "alert('Type your message here');";
strScript += "window.location='TestPage.aspx';";
strScript += "</script>";
this.ClientScript.RegisterStartupScript(this.GetType(), "Startup", strScript);

This code will display an alert box and when 'OK' button is clicked it will redirect to TestPage.aspx page.

3 comments:

Anonymous said...

Very much helpful...

Anonymous said...

Thnx for help...

Anonymous said...

than you

Post a Comment