Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Timed redirect without javascript? 1

Status
Not open for further replies.

jacktripper

Programmer
Joined
Dec 5, 2001
Messages
124
Location
US
I've done a lot of simple pages which redirect after X number of seconds using a javascript function called from the body onload parameter. But, I'm confused on how I can do this with an ASP.NET web form.

So far, I've been able to call some simple javascript functions based on a button event in the code-behind. But how can I run a javascript function from within a VB function?

Here is what I'm trying to do: I've got a web form with validation. It passes data to a web service, and gets results from the service. Based on those results, I want to have display a message on the same page (not a popup or a new page) that says "Thanks. You will be redirected to your previous location in 5 seconds." Then it auto-redirects like the javascript:history.go(-2) function.

Is this doable with javascript in ASP.NET? If I have to use javascript, how can I call a timed redirect function based on the results from a web service?

Many thanks.
 
So all I do is add that line and then put a Response.Redirect after it?
 
Sorry, you also need this imports:
Imports System.Threading
 
Oh, whoops. But how can I reference the javascript function then? I see how this pauses the scripting for 5 seconds, but I still need the redirect to reference the client-side script for javascript:history.go(-2)
 
I've done a lot of simple pages which redirect after X number of seconds using a javascript function called from the body onload parameter.
There's no difference between the simple page and the ASP.NET page really as ASP.NET simply omits HTML.

So, one method would be to simply use Page.RegisterStartUpScript (it's in the ClientScript class not Page if you are using version 2.0 of the framework) and pass in your JavaScript.

Another method would be to use the Attributes.Add of the body tag to add the onload event.


____________________________________________________________

Need help finding an answer?

Try the Search Facility or read FAQ222-2244 on how to get better results.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top