views:

53

answers:

3

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
UpdatePanels are a bit heavy for regular polling; especially when there's a lot of Viewstate. I'd go for PageMethods.
Yellowfog
@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
+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
Why not use session state instead of a file?
Pierreten
Feel free. The sort of nuts-and-bolts implementation is up to you.
Just Jake
But won't polling the service, while it's synchronously blocking with the long running process not work?
Pierreten
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
A: 

Ajax calling a Web Service is how I would do it.

Kolten