There is no way for server side ASP.NET code to call a web browser and notify it of new data. Therefore, you will have to use JavaScript to poll the server for new data. There are various ways to do this. As an example, we could use Server-side page Methods , which could tell the client if there is more data and when all the data has been loaded.
[WebMethod] public static bool IsNewDataAvailable(int currentClientRows) { return dataCollectedSoFar.Count > currentClientRows; } [WebMethod] public static bool IsFinished() {
You need to call the IsNewDataAvailable method at regular intervals. A simple JavaScript timer should do the trick.
When new data appears, you need to redisplay the GridView. Again, there is more than one way to do this, but a nice and easy way would be to include the GridView in the UpdatePanel next to the button with the style = "display: none;" to keep it hidden. Then, if there is new data, simply call the JavaScript click method on the button to refresh the contents of the update panel.
<script> var timerId = setInterval("checkForData()", 5000); function checkForData() { </script> . . . <asp:UpdatePanel ID="myUpdatePanel" runat="server"> <ContentTemplate> <asp:GridView ID="myGridView" runat="server"> . . . </asp:GridView> <asp:Button ID="myHiddenButton" runat="server" style="display: none;" OnClientClick="myHiddenButton_Click" /> </ContentTemplate> </asp:UpdatePanel>
Finally, to populate the server-side GridView, you can continue to use ThreadPool and simply visualize all the data that you have every time. For instance:
protected void myHiddenButton_Click(object sender, EventArgs e) { myGridView.DataSource = dataCollectedSoFar; myGridView.DataBind(); }
source share