[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

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

Posted on 2008-11-19
13
Medium Priority
?
292 Views
Last Modified: 2012-05-05
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
0
Comment
Question by:penson
  • 7
  • 6
13 Comments
 
LVL 13

Expert Comment

by:Onthrax
ID: 22999502
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
 

Author Comment

by:penson
ID: 22999545
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
 
LVL 13

Expert Comment

by:Onthrax
ID: 23001974
You could use a javascript refresh which gets initiated when the page first loads and gets cancelled when the page gets closed.
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:penson
ID: 23055906
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
 
LVL 13

Expert Comment

by:Onthrax
ID: 23055973
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
 

Author Comment

by:penson
ID: 23056021
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
 
LVL 13

Accepted Solution

by:
Onthrax earned 500 total points
ID: 23056093
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
 

Author Closing Comment

by:penson
ID: 31518455
thanks I will try this
0
 

Author Comment

by:penson
ID: 23081562
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
 
LVL 13

Expert Comment

by:Onthrax
ID: 23083816
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
 

Author Comment

by:penson
ID: 23086228
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
 

Author Comment

by:penson
ID: 23090282
Could you attach a simple example you used with a master page and a content page?
0
 
LVL 13

Expert Comment

by:Onthrax
ID: 23093767
Ok. Let's leave this thread and continue in your supplemented one..
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Lots of people ask this question on how to extend the “MembershipProvider” to make use of custom authentication like using existing database or make use of some other way of authentication. Many blogs show you how to extend the membership provider c…
I recently went through the process of creating a Calendar Control of events with the basis of using a database to keep track of the dates that are selectable, one requirement was to have the selected date pop-up in a simple lightbox.  At first this…
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …
As many of you are aware about Scanpst.exe utility which is owned by Microsoft itself to repair inaccessible or damaged PST files, but the question is do you really think Scanpst.exe is capable to repair all sorts of PST related corruption issues?
Suggested Courses
Course of the Month20 days, 3 hours left to enroll

873 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question