ASP.NET Asynchronous label update

后端 未结 2 1917
轻奢々
轻奢々 2021-01-03 10:21

I have a process that runs long, and I want to update a label on the page as the process goes along, but I\'m not having any luck.

Here\'s the aspx:

         


        
相关标签:
2条回答
  • 2021-01-03 11:18

    You can use SignalR library for this to get this work.

    See the sample here

    In the given sample, after the server side dosomething() async task is done, it calls the client side notifyResult() to update the view.

    Also see : Is there a way to exclude a Client from a Clients.method call in SignalR?

    0 讨论(0)
  • 2021-01-03 11:26

    This is not going to work. The problem is that asp.net works on a request/response model. In order to receive any updates the client (browser) needs to request the information from the server. In order for your label to be updated you will need to send a request for its new value to the server which in turn works out what the value is and responds with the appropriate value for you to display.

    The easiest method would be to write this using AJAX with some way of timing the requests for data, or instead to set a timer and have the page refresh itself on a set timer. The bottom line is you need the page to poll for the updated value, just because you update the value in your worker process does not mean the browser will receive this new value.

    I know you said you didnt want to use AJAX but take a look at the following jQuery.get() to get a better understanding of what you need to do.

    0 讨论(0)
提交回复
热议问题