Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 354
  • Last Modified:

ASP.Net How to set a 5 second Response.Redirect when a button is fired.

I've searched High and low looking for a VB script that will redirect a user to another page after 5 seconds when a button is clicked.  All I seem to find is javascript and META tag refreshes that fire events 5 seconds after a page is loaded.  I'd really rather not have a whole separate file just to perform this action.  Any ideas?  No external links please, VB samples only if possible
0
Mose_
Asked:
Mose_
1 Solution
 
raterusCommented:
Is this what you want?

Sub Button_Click(...)
  System.Threading.Thread.Sleep(5000)
  Response.Redirect("somepage.aspx")
End Sub
0
 
softplusCommented:
I'd prefer not to do it on the server side, it's a waste of resources. Do the following:

Sub Button_Click(...)
   Response.AppendHeader("Refresh", "5;somepage.aspx")
End Sub

After clicking the button, it will return to the page you had open, now with the meta-refresh tag in the header to redirect to the other page after 5 seconds. However, this is dependant of the client/browser, so there's a possibility it can break. But why should you want to wait? The web's slow as it is anyway :)
John
0
 
softplusCommented:
You could also do this:
Sub Button_Click(...)
  Response.Redirect("gosomewhere.aspx?page=somepage.aspx")
End Sub

and on the gosomewhere.aspx, you get the desired URL, add the Refresh= metatag into the header, show a short text, e.g. "Redirecting to ... just a moment please ....  ". It would make it more transparent for the user.
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
raterusCommented:
Actually, when you "sleep", asp.net tells the server to go do something else for that 5 seconds and come back to me then, so you really aren't wasting any resources.  I do prefer John's solution though, my solution will make it look like the page took 5 seconds to load, at least with John's the page will be immediately returned, where you can give them information like "blah blah, will be redirected in 5 seconds..."
0
 
nauman_ahmedCommented:
I will recommend you use the Timers class as it will be more efficient. Using Thread.Sleep() will block the thread to perform any kind of functions:

URL: http://www.asp101.com/samples/time_aspx.asp


Example:
---------------
URL: http://www.411asp.net/home/tutorial/specific/timers/classes/timer

private void StartTimer()
{
    System.Timers.Timer myTimer = new System.Timers.Timer();
    myTimer.Interval = 5000;
    myTimer.Elapsed += new System.Timers.ElapsedEventHandler(myTimer_Elapsed);
    myTimer.Enabled = true;
}

protected void myTimer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
{
    //do some work
}

HTH, Nauman.

0
 
Mose_Author Commented:
Thanks guys, I'm trying to put a couple of different conditions for when I exit a page to return to the main datagrid.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now