Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

AutoRefresh with condition

Status
Not open for further replies.

peac3

Technical User
Jan 17, 2009
226
AU
Hi Guys,

I have had function for the grid which returning the value of database which determines whether the job is currently running.

I would like to add into the function if the job is currently running I would like to do auto refresh every 5 seconds.

I have searched in google, there is no specifically like this and We dont want to use Ajax time control as we would like to make it simple and refresh the whole page.

Could you guys shed me some light for this?
Any input will be appreciated.

Thanks in advance guys,
 
are you talking about the web? if so then this is a client side issue, not a server issue. remember once the request is sent from the server to the client the server forgets about what just happened.

you will need a javascript timer to instruct the page to refresh. there may also be some html meta-data tags you can include to instruct the browser to refresh the page.

We dont want to use Ajax time control as we would like to make it simple and refresh the whole page.
ajax is actually very simple with libraries like jquery, jquery-tmpl and backbone. you also get full control over rendering which you may need when the client/users come back and say "it works, but can it happen like this instead?"

Jason Meckley
Programmer

faq855-7190
faq732-7259
 
Have a non-programming solution (sorta)

Firefox has a free addin for page refreshing.
As long as you're okay with both Firefox, and the page refreshing regardless of the job status, it's a quick and dirty way to get a HUD to show correct values.

Otherwise you're stuck writing client side code. You can invalidate the page state server side, but that's not going to cause a delayed round trip.

Lod

You've got questions and source code. We want both!
 
Hi Guys,

Thanks for the info,
at the moment I have used the javascript code chucked into the c# server code like this

Code:
if(the job is running)
{
Page.ClientScript.RegisterStartupScript(GetType(), "refresh", "window.setTimeout('var url = window.location.href; window.location.href = url',5000);", true);
}

As you can see the code above is refresh every 5 seconds.
Between the job 1 and 2 there is a gap up to 30 seconds to wait.

How do I create the code for this:

-wait 30 seconds
-refresh the page once.

Both codes above to initiate refresh page for the next job.
Thanks guys,
 
why not ask in the appropriate forum? being this will be executed on the client forum216 is your best place to start. for help with the code behind forum855 is the place to post.

Lod, I like the solution. simple, clean and efficient.

Jason Meckley
Programmer

faq855-7190
faq732-7259
 
Sometimes my best work comes from not doing anything :)

peac3, you're going to need to add an else condition. change your timeout from (5)000 to (30)000.

If you only want a single refresh then you're going to have to store something in session to indicate how many times you have refreshed the page. Keep in mind you're going to want to add a bit to clear that value if a job is running.

Lod

PS: too bad you can't move a thread...

You've got questions and source code. We want both!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top