Forum



18:57

30/08/2011

Hello All.
I am having trouble with timers and jqgrid. I have a single jqgrid on my page and I am using the javascript setInterval function to call a function every 10 minutes that calls reloadGrid to keep the contents of the grid updated. This works well.
Now I want to give the users a button they can click to refresh the grid straightaway. The button just calls the same javascript function (that calls reloadGrid). This works in itself but once that button has been used the grid is not updated automatically anymore. Alert() calls in the javascript function stop showing up. The 'manual' refresh button works when it is pressed subsequent times though.
Has anybody got any ideas why this is happening or what I can do to keep the background refresh happening ? I have tried using the setTimeout function, I have tried stopping the timer with clearTimeout or clearInterval and then restarting the timer after the reloadGrid call but nothing seems to help. The automatic refresh function never gets called after the user manually runs the reloadGrid function ?!?!
There isn't much code to look at but here is what I am doing in case it helps:
javascript function that does the refresh:
function reloaddata() {
$("#table").trigger("reloadGrid");
}
// this is being run when the page loads ( 6 secs for testing, 10 minutes normally)
setInterval( "reloaddata()", 6000 );
// and I have an image button that the user clicks to refresh the page straightaway
<asp:ImageButton ID="ImageButton1" runat="server" onclientclick="reloaddata()"ImageUrl="~/Images/reload.png" />
Thanks in advance for any help.
Andrew
14:53

30/08/2011

After trying a few more things I have worked out what was happening. No problem with jqgrid or timers, just my understanding of how asp.net works. When the Imagebutton was clicked it performed the reload but also did a postback and because I am only registiering the start up script when it is not postback when the page reloaded the timer was not initiated and therefore the reload function was never called again. So I have changed the control from an imagebutton to just an image (which doesn't perform a postback when it is clicked) and it is working as I had planned now.
Most Users Ever Online: 715
Currently Online:
28 Guest(s)
Currently Browsing this Page:
1 Guest(s)
Top Posters:
OlegK: 1255
markw65: 179
kobruleht: 144
phicarre: 132
YamilBracho: 124
Renso: 118
Member Stats:
Guest Posters: 447
Members: 11373
Moderators: 2
Admins: 1
Forum Stats:
Groups: 1
Forums: 8
Topics: 10592
Posts: 31289
Newest Members:
, razia, Prankie, psky, praveen neelam, greg.valainis@pa-tech.comModerators: tony: 7721, Rumen[Trirand]: 81
Administrators: admin: 66