I was wondering if anyone had an easy way to wire up javascript event handlers to events happening on the server-side. I have a long running process that includes a lot of steps, and would like the client to be continually updated with new information as the steps transition. Will this involve some sort of polling mechanism?
A:
would it be possible to use an update panel to do this with maybe a timer? it's sort of how I would do it.
Course, this depends on what you're doing already. I'm assuming you're using Forms...
drachenstern
2010-06-30 17:43:44
UpdatePanels are a bit heavy for regular polling; especially when there's a lot of Viewstate. I'd go for PageMethods.
Yellowfog
2010-06-30 18:36:24
@Yellowfog - I agree they're heavy, like I said it just depends on what the effect is that he's aiming for. But I did forget about PageMethods...
drachenstern
2010-06-30 19:24:17
+2
A:
Send an AJAX or JSON request from the client every so often asking for status.xml
. Then, on the server, when something changes, just quickly write a new line to status.xml
the same way you would to the console. You can use setInterval( function, timeBetweenRuns )
in Javascript to do this regularly.
Just Jake
2010-06-30 17:45:32
But won't polling the service, while it's synchronously blocking with the long running process not work?
Pierreten
2010-07-01 23:23:11
this is why I suggested just printing a line to an XML file. You can do that from your long running process, and then serve to the client not using ASP but as a simple flat HTTP request
Just Jake
2010-07-02 18:32:26