Timer in ASP.Net

  • Thread starter Thread starter csgraham74
  • Start date Start date
C

csgraham74

HI all,

I want to implement this scenario: I need my ASP.NET website to
check a SQL table every 30 seconds and if there is a change to display
a message to user. I have created a panel control (pnlMessage) and
placed the message on it also made it default to visible = false. I
have placed a Timer control on my ASP.NET Web Form and set its Interval
= 30000 (30 seconds) it fires ok every 30 seconds and the code executes
it hits the line pnlMessage.visible = True but the panel doesnt
display. When I am debuging it also seems like the timer is still
runnig regardles of me debugging and also all my cookies seems to be
not readable any more. I think i am not using this control correctly
can someone give me an example pls?
 
This is not exactly answer to your question, but is it possible to use more
simple approach:
<meta http-equiv="refresh" content="30">
 
Because of the disconnected state of web apps, this is a tricky problem. Ajax
(Asynch JavqaScript and XML) might be a solution (poll without refreshing the
entire page) as would a page refresh (META tag will work here). With 2.0, you
have the ability to send out a message when data is stale, which works
extremely well in SQL Server 2005 (both due out Nov 7), but you still have to
work a bit with the plumbing.

If stale data is a problem due to editing, consider working in concurrency
protection rather than polling, as it is easier to handle and well documented.

--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA

***************************
Think Outside the Box!
***************************
 
Seems to me that you are expecting a timer, created on the server side, to
work with the page framework dynamically. You can change the properties of
controls up and including to the PreRender event. Remember, web programming
is disconnected. Your page is already rendered to the browser adn there's
no tie between the server code and the client anymore. This would work in
windows client,but not web forms.

Check out:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnaspp/html/ASPNetSpicedAjax.asp

it uses Ajax to poll a database for changes (sample #2). It should set you
on the right track...

Karl
 
The server cannot raise an event to a client machine because of the
disconnected architecture of the internet.
All communications must be initiated by the client.
Therefore you may want to have the browser request an update every 30
seconds.

Here are some options:

You could use a refresh meta tag
<meta http-equiv="refresh" content="30">

You could use a JavaScript timer to refresh the page every so often:
http://www.crowes.f9.co.uk/Javascript/timer.htm

Dart has a really nice AJAX-based timer control:
http://www.dart.com/LiveTimer.asp
 
create a webservice. Add function to webservice to get data you need and in
time interval that you want.
Create a windows forms control that consumes the service and displays the
status.
Using the object tag put the control on the website.
 
Back
Top