How to set up automatic refresh on an asp.net site

I want to have a refresh that recalls the database to pick up changes.  I have timers set up on different pages that call the database. (using System.Timers.Timer() )  But if a user moves to different page that has another timer I get more than one timer calling the database and this is bad for performance. What is the standard way to handle an automatic refresh?
Thanks in advanced
pensonAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

OnthraxCommented:
I'd forget about using a timer and approach it a little differently.

Set up a shared property that contains a date + time. Now every time a page request is made, check if the interval you want is passed and if so, update your stuff from the database and set the shared property to that current time.

Example:
10:00 am - page request. Check DateTime variable. If Current Time - DateTime > 10 do stuff and update DateTime variable. If not do nothing.

This does not damage performance as only one variable is maintained and a 'simple' compare is sufficient to check whether or not do take action.

Hope this helps.
0
pensonAuthor Commented:
How do I refresh the screen if there are no page requests?
The user logs in and just watches the screen which needs to update every 5 seconds on its own.
0
OnthraxCommented:
You could use a javascript refresh which gets initiated when the page first loads and gets cancelled when the page gets closed.
0
Python 3 Fundamentals

This course will teach participants about installing and configuring Python, syntax, importing, statements, types, strings, booleans, files, lists, tuples, comprehensions, functions, and classes.

pensonAuthor Commented:
But then I only get updates when the user first loads the screen right? I need the screen to keep updating on it's own every 5 seconds.
0
OnthraxCommented:
every 5 seconds.. wow. okay.. then i'd do it a little differently again hehe..

Put the stuff you want updated into an updatepanel.
Create a little javascript that will trigger a refresh on the updatepanel every 5 seconds.

This way when the page gets loaded, the javascript will get fired and will update the content inside your updatepanel every 5 seconds, which is exactly what you want if I'm correct now..

You can find here how to update the updatepanel through javascript:
http://www.asp.net/learn/ajax-videos/video-172.aspx

Good luck.

0
pensonAuthor Commented:
I will look at the link. Does the javascript timer stop when the user goes to another page? Or can I stop it with some javascript event? Is there some javascript event that fires when a user leaves the page?
0
OnthraxCommented:
Yes as javascript is client based when the browser moves away from the page, either by closing the browser or loading another page, all javascript on that page will stop.

There is an unload even that will fire when the browser moves away from the page.
For an example check: http://www.dcs.uwaterloo.ca/~anderson/JavaScript/ex_load_unload.html
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
pensonAuthor Commented:
thanks I will try this
0
pensonAuthor Commented:
I am having a difficult time getting this to work because I am using a master page. When using a master page if you call a postback from javascript I get IsInAsyncPostBack = false so it is not an ajax post back and you get a page that flickers.
0
OnthraxCommented:
I am using the same technique and also a masterpage and it's working fine.

Perhaps you should create a new thread for this 'new' problem. Post back the link and I'll assist you again, but this way you might get more input from other people as well to get your problem fixed a.s.a.p.
0
pensonAuthor Commented:
I created a new thread for this problem and posted the code for the master and child pages.
Are you using VS 2008 .net 3.5?

Ajax not working with master pages

http://www.experts-exchange.com/Programming/Languages/Scripting/AJAX/Q-23950269-Ajax-not-working-with-master-pages.html

thanks in advanced
0
pensonAuthor Commented:
Could you attach a simple example you used with a master page and a content page?
0
OnthraxCommented:
Ok. Let's leave this thread and continue in your supplemented one..
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ASP.NET

From novice to tech pro — start learning today.