Redirect page automatically

how to automatically redirect an ASP.NET page to another after 1 minute using C # code.

+6
source share
8 answers

You can use something like this:

<meta http-equiv="Refresh" content="60; url=http://your.new/url/here" /> 

"60" is the time in seconds to wait for a page redirect.

+18
source share

Try using this code: Here 5 means redirecting after 5 seconds and makes it 60 if you want to redirect after 1 minute.

 protected void btnRedirect_Click(object sender, EventArgs e) { Response.AddHeader("REFRESH", "5;URL=YourNextPage.aspx"); } 

This code can also be placed in the Load event of the page so that it redirects to another page after loading the current page.

+9
source share

You cannot use C # code to redirect after a certain time from the server side, since C # runs on the server side. You can do this by specifying a meta tag in your HTML:

 <meta http-equiv="refresh" content="300; url=newlocation"> 

You can write C # code to create this tag. Here is an example:

 HtmlMeta meta = new HtmlMeta(); HtmlHead head = (HtmlHead)Page.Header; meta.HttpEquiv= "refresh"; meta.Content = "300; url=newlocation"; head.Controls.Add(meta); 
+6
source share

you can do this using:

 System.Threading.Thread.Wait(60); Response.Redirect("Somepage.aspx"); 

Edit:

 System.Threading.Thread.SpinWait(60); Response.Redirect("Somepage.aspx"); 
+2
source share

Note. The SpinWait parameter is a loop, not a second, as described above.

Taken from the MSDN page http://msdn.microsoft.com/en-us/library/system.threading.thread.spinwait.aspx

The SpinWait method is useful for implementing locks. Classes in the .NET Framework, such as Monitor and ReaderWriterLock, use this method internally. SpinWait, in fact, puts the processor in a very tight loop, with the loop count indicated by the iteration parameter. Thus, the waiting time depends on the processor speed.

+2
source share

There are many ways to do this, but I like to use this code because it works well when used in a variety of circumstances.

 HtmlMeta oScript = new HtmlMeta(); oScript.Attributes.Add("http-equiv", "REFRESH"); oScript.Attributes.Add("content", "60; url='http://www.myurl.com/'"); Page.Header.Controls.Add(oScript); 
+1
source share

Doing this on the client would be better than doing it on the server.

You will need to use javascript to set the timer and then redirect.

See this on how to redirect: How to redirect to another web page in JavaScript / jQuery?

See this for timers:
Javascript loop timer

http://www.w3schools.com/js/js_timing.asp

http://www.elated.com/articles/javascript-timers-with-settimeout-and-setinterval/

0
source share

I like to do my stuff in JavaScript :-) I love JS. Here is my JS solution.

 <script type="text/javascript"><!-- setTimeout('Redirect()',4000); function Redirect() { location.href = 'your-redirect-to-link'; } // --></script> 

The page will be redirected after 4 minutes. You have to put it in your head, obviously.

0
source share

All Articles