Stephen McCrea wrote:
I am new to asp. I tried implementing a timer in a System.Web.UI.Page
derived class to perform periodic refreshes of the interface and calls to
a web service but it does not seem to work as I expected. I could not set
its SynchronizingObject field.
When the page first loads I see that the timer has been operating for 2 or
3 seconds already (it updates the text field of a label control), but
whenever I perform other refreshes of the interface it does not seem to be
working properly - it no longer updates the label.
Could someone help me or point me to a good reference online or hardcopy?
Thank you...
Hello Stephen,
It's not possible to use timers like this, at least not if you're
using the web forms framework with ASP.NET. As soon as your page
object has finished the "render" phase ( sent its output as a
response back to the client ), your page object will be destroyed.
Next request from the client, a new instance will be created again.
In this scenario, the only way to refresh the client periodically
is by using some client side JavaScript.
If you don't use the web forms framework, you can keep the response
stream open and periodically send JavaScript to the client which
contains instructions to update the user interface. In this scenario,
you do have to watch out for timeouts, f.i. there may be limits
to the amount of time a web browser will wait for a response
to finish and there may be limits to the amount of time an
aspx may run on the server. Also, I believe this doesn't
work correctly in all browsers, because some browsers
only begin executing JavaScript when they received
the complete response.
Best regards,
Eric