In this article I will explain how to automatically redirect to another page after some delay of say 5 or 10 seconds in ASP.Net.
There are situations when you want to redirect the user to a certain page after certain amount of time interval in other words delayed redirection your asp.net web application. In that case you can take help of the Refresh Meta tags.
There are several ways of adding Meta tags to the page, I am going to add a Meta tag that will redirect automatically to another page after delay of 5 seconds.
 
HTML Refresh Meta Tags
The HTML Refresh Meta Tag consists of two properties.
1. http-equiv – Here we set the type of Meta tag. In our case we need to use the Refresh Meta tag and hence the value will be Refresh.
2. content – Here we need to set the number of seconds i.e. delay after which it will redirect and also the URL of the page separated by semicolon. For this article I am setting delay of 5 seconds.
 
 
1. Adding the Meta tag in Head section of the page
The simplest way is to add the Meta tag directly to the ASPX page. The following HTML Markup contains a Meta tag added in the Head section of the page.
<head runat="server">
    <title>Meta Tags Example</title>
    <meta http-equiv="Refresh" content="5;url=Page2.aspx" />
</head>
 
 
2. Adding Meta Tag using HtmlMeta class
 For this method you will need to import the following namespaces
C#
using System.Web.UI.HtmlControls;
 
VB.Net
Imports System.Web.UI.HtmlControls
 
In the following method, an object of HtmlMeta class is created for which HttpEquiv and the Content properties are set and then the object is added to the Page controls.
C#
protected void Button1_Click(object sender, EventArgs e)
{
    HtmlMeta meta = new HtmlMeta();
    meta.HttpEquiv = "Refresh";
    meta.Content = "5;url=Page2.aspx";
    this.Page.Controls.Add(meta);
    Label1.Text = "You will now be redirected in 5 seconds";
}
 
VB.Net
Protected Sub Button1_Click(sender As Object, e As EventArgs)
    Dim meta As New HtmlMeta()
    meta.HttpEquiv = "Refresh"
    meta.Content = "5;url=Page2.aspx"
    Me.Page.Controls.Add(meta)
    Label1.Text = "You will now be redirected in 5 seconds"
End Sub
 
 
3. Adding Meta Tag by appending Response Header
 In the following method, Meta tag is added to the page using the Http Response header.
 
C#
protected void Button2_Click(object sender, EventArgs e)
{
    Response.AppendHeader("Refresh", "5;url=Page2.aspx");
    Label1.Text = "You will now be redirected in 5 seconds";
}
 
VB.Net
Protected Sub Button2_Click(sender As Object, e As EventArgs)
    Response.AppendHeader("Refresh", "5;url=Page2.aspx")
    Label1.Text = "You will now be redirected in 5 seconds"
End Sub
 
 
Demo
 
 
Downloads