views:

372

answers:

1

Hello. I am needing to create something like a lock timer(a little thing that just updates a lock time in a database). I thought the Timer control would suite my needs, but whenever the Timer control causes a partial post back, recently typed text in a textbox can disappear(inbetween the post back begin and post back end) and it loses focus.

Because this is only a lock timer, I do not need to refresh any part of the screen, I basically just need to tell the server "hey, don't free my lock, I'm still on this page". So is a Timer control even necessary? Is there an easier way to do this is pure javascript? The only thing I need to know is an ID, which could be kept as a hidden field(and therefore accessible from javascript by DOM)

anyone have any input on how to tune the timer control or a quick javascript way to do it?

edit: also, I have the updatepanel that contains the timer control outside of the update panel containing the textbox control

A: 

If I understand it correctly you need a method which will update the datetime in the database at periodic intervals.

For that you can simply use Ajax. The window.setInterval is a JavaScript function which will fire a piece of code at regular intervals.

window.setInterval(foo,5000);

The above code fires the foo method every 5 seconds.

The only thing you need to lookup is how to call the database. Since, you are already using MS Ajax I suggest you check out ScriptManager control which contains a section for services. Check out the following post which consists of a simple example of how to call WebService methods using MS Ajax:

http://azamsharp.com/Posts/83%5FUsing%5FFireBug%5FProfiler%5Fto%5FDig%5FDeep%5Finto%5FMS%5FAJAX%5Fand%5FJQuery%5FAPI.aspx

azamsharp
is there no easier way than creating a web service?
Earlz
Well, you can always call PageMethods. You will need to decorate the page methods with [WebMethod] attribute.
azamsharp