How to simulate a client-side Timer object in ASP.NET

esposito

Centurion
Joined
Jul 11, 2003
Messages
103
Location
Perugia - Italy
Hello, I'm new to ASP.NET and I use Web Matrix to create my Web pages.

As you know, the Timer control in not present in the tool box. So, I would like to know if and how it is possible to simulate it.

In particular, I would like to get a 10-second countdown on a label control (Interval = 1 second). I believe you need to write some Javascript code to make it work, since it is a client-side function and, unfortunately, I haven't done much practice with that language.

Any help will be appreciated.

TIA
 
The timer is probably slightly more complicated than it appears.
2 Suggestions.
1) You can use javascript to fire an event by setting the timeout property
2) Do a search for WebTimer. I have found it before. It's free and all you have to do is add it to the toolbox and wazzaaam...you have a timer that fires a server side event.

-lp
 
You can use the javascript Window.setTimeout() function to call a function after a delay has passed, in your case 1 second. Use something like:

setTimeout("countdown()", 1000);

to call a countdown() function that updates your label control on the client side (which is rendered simply as a div tag). Have your countdown() function call itself using this setTimeout() function until you hit zero.

I suppose there might be a better ".NET" way, but I like using javascript like this for simple client side functionality.

HTH
 
Thank you for your reply. I know I may be asking too much, but please could you give me a step-by-step example of how to create and call the Javascript function you suggested? Unfortunately, I'm new to Javascript.

TIA

akiaz said:
You can use the javascript Window.setTimeout() function to call a function after a delay has passed, in your case 1 second. Use something like:

setTimeout("countdown()", 1000);

to call a countdown() function that updates your label control on the client side (which is rendered simply as a div tag). Have your countdown() function call itself using this setTimeout() function until you hit zero.

I suppose there might be a better ".NET" way, but I like using javascript like this for simple client side functionality.

HTH
 
Back
Top