Here is the situation. I need to hit ~50 servers and grab some data from a file. I then want to display a few rows for each in an ASP.NET GridView control.
I tried doing this with Threads/ThreadPool and successfully gather all the data in session.
What I’d like to do, and what I am having a hard time figuring out, is update the grid for the user after each server is done loading.
If I put the databinding code in the thread, it will only display whatever has loaded by the time the response is sent back to the client. If I take it out of the thread, I’d have to wait until all threads were done to send the response, and that doesn’t do what I want.
Anyone have any ideas? I seeing some stuff about Asynchronous Client Callbacks, but I’m not sure if that’s what I need to be using. I have no idea how to manipulate a GridView from Javascript.
Thanks for any help you can provide.
There’s no way for the server side ASP.NET code to poke the web browser and to tell it that there’s new data available. So you’ll have to use to JavaScript to poll the server for new data. There are various ways of doing this. One example would be to use Page Methods on the server side that could tell the client whether there’s more data available and when all the data has been loaded.
You need to call the IsNewDataAvailable method at regular intervals. A simple JavaScript timer should do the trick.
When there is new data available, you’ll need to re-render the GridView. Again, there’s more than one way to do this, but a nice and simple way would be to put the GridView inside an UpdatePanel along side a Button with a style=”display: none;” attribute to keep it hidden. Then if there is new data available, simply call the JavaScript click method on the button to update the contents of the update panel.
Finally, to populate the GridView on the server side, you can continue to use a ThreadPool and just render all the data you have each time. For example: