Tuesday, October 29, 2013

Redirect to Another Page On Clicking OK in JavaScript Alertbox

Page Redirection after client script does not show the popup or alert box added to the code using ClientScript.RegisterStartupScript 

Example:

this.Page.ClientScript.RegisterStartupScript(this.GetType(), "alert", "alert('Operation Completed')", true);

 Response.Redirect("~/default.aspx"); 


In this code you will not get the alertbox and will be simply redirected to default.aspx page.

Modify the code like below

this.Page.ClientScript.RegisterStartupScript(Page.GetType(), "alert", "alert('Operation Completed.');window.location='default.aspx';", true);  

This will show the alertbox and upon clicking OK you will be redirected to default.aspx page                  

No comments:

Post a Comment