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

2
0

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]

//Code for C#
Response.AppendHeader(“Refresh”, “5;url=https://www.aspneto.com”);

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

//Code for Vb.net
Response.AppendHeader(“Refresh”, “5;url=https://www.aspneto.com”)

Download Example

[wpdm_package id=’5429′]

Git Repo

LEAVE A REPLY

Please enter your comment!
Please enter your name here
Captcha verification failed!
CAPTCHA user score failed. Please contact us!