Auto Redirect on form submit after showing success/failure message.

This post illustrates the scenarios like how to achieve auto redirect on form submit from parent window to child window or auto redirect to specified url on submitting the form giving a delay for showing the success or failure message.

Scenario 1: Redirect and refresh the parent windows on form submit from child popup window.

This piece of code works for the scenarios where one need to redirect and refresh the parent page on submitting the form on child popup window.

If you need to delay the redirection for a while after submitting the form, you can try adding the thread.sleep() method before this snippet.

    Type type = this.GetType();  
    String url=;
    string js = "";  
    js += "window.opener.location.href='" + url + "';";  
    js += "window.close();";  
    ClientScript.RegisterStartupScript(type, "redirect", js, true);  

Here we are registering the startupscript and implementing the logic using window.opener.location.href property of javascript.

Scenario 2: Submit form and open specified url with a delay of 5 seconds.

ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "success", "alert('Submitted Successfully.'); setInterval(function(){location.href='';},5000);", true);

The approach works for scenarios where it requires to show the success or failure message after submitting the form and then redirect to specified url with the given delay time. The above script also shows an alert box to display the message.