March 26, 2013

Redirect after 5 seconds

This post shows the demonstration on how to redirect to another page after some seconds in Asp.net application. There are two types of code is use. One using meta tag and other one is use JavaScript. 

Use this line within <head> section of page.

<meta http-equiv="refresh" content="N; URL=other-web-address">

Here: section of page.

  • Replace N with number. For Example 5, so page will be redirect after 5 seconds.
  • Set URL to where redirection occur
The modified code will be

<meta http-equiv="refresh" content="10; URL=http://www.google.com">

If you are using Content page then instead of using above method use JavaScript code as

<script type="text/javascript">  

    delayRedirect('Login.aspx'); 

    function delayRedirect(url)
    {
        var Timeout = setTimeout("window.location='" + url + "'",5000);
    }
    
</script> 


Hope you understand well. Let me know if anybody face any issue. Stay tuned.