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" />
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!