Home Asp.net Automatically Redirect a Web Page or URL after 5 Seconds in Asp.net

Automatically Redirect a Web Page or URL after 5 Seconds in Asp.net

51
0
Redirect Page on Button Click

In my previous tutorials, I’d explained how to auto-refresh a webpage in every 10 seconds, how to redirect to a specificied url or webpage on button click, gridview inline insert update delete, and other more cracking tutorials on Asp.net, JavaScript, jQuery here.

Now here in this tutorial, I’ll explain automatically redirect a Web page or URL automatically in a specific interval or time span, let’s say in every 5 seconds.

We can do this by using a simple one line of HTML code, by using html meta tag. Here is the example:

<meta http-equiv="refresh" content="5;url=https://www.aspneto.com" />
Note: You just need to place the above single line of code in html head tag. Here, 5 in content=”5;” is a time duration in seconds. If you want to specify your webpage URL then replace the “https://www.aspneto.com” URL by your webpage URL from the above example, else for the same page refresh, we don’t need to specify any URL, like this.

Automatically redirect a web page after 5 seconds

Auto-refresh Webpage – [.aspx]

Following is the complete HTML Markup code:

<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <meta http-equiv="refresh" content="5;url=https://www.aspneto.com" />
    <title>Auto Redirect to page or URL in 5 seconds</title>
</head>
<body>
    <form id="form1" runat="server">
        <div>
            <br />
            <br />
            <h3>Wait for 5 seconds, It'll automatically redirect you to the URL</h3>
        </div>
    </form>
</body>
</html>

If you want to implement this functionality from code-behind, it’s also as simple as that. Simply add the following line of code on Page_Load and ignore the above example.

Automatically redirect a Web Page Using C# – [.cs]

If you’re using C#, use following code-behind statement to redirect to a webpage:

Response.AppendHeader("Refresh", "5;url=https://www.aspneto.com");

Automatically redirect a Web Page Using Vb.net – [.vb]

If you’re using Vb.net, use following code-behind statement to redirect to a webpage:

Response.AppendHeader("Refresh", "5;url=https://www.aspneto.com")

Download Example

Git Repo

That’s it, by using this way you can automatically redirect any html or asp.net web page url after N seconds. In above example, I’ve used 5 seconds but you can change it to any number you want.

Let me know if you’ve any questions or doubts about this tutorial by writing down your queries in comment below. I would be happy to provide you my feedback as soon as possible.

Happy coding!

Previous articleAuto-refresh Webpage in Every 10 Seconds in Asp.net C# Vb.net
Next articleRedirect Page on Button Click in Asp.net using JavaScript jQuery
Hi there, I am Mayank, the man behind Technical Mack. I started AspnetO with a motive to educate people on various programming languages ranging from beginners to expert level. Through this blog, I aim to provide more insightful content.

LEAVE A REPLY

Please enter your comment!
Please enter your name here

18 + 19 =