Click here to Skip to main content
15,891,473 members
Please Sign up or sign in to vote.
1.60/5 (3 votes)
See more:
Hi,
I am working on .NET web application using C#. I am getting some data from a service which is time in page load. So I am calling the method asynchronously so that the UI will load quick and in background the data will be getting from service. After completion of data getting, I am binding the data to a gridview and updating a label text. But this updation is not showing/reflecting in UI. How can I do it? Please let know.

Here is my code.

GDelegate del = new GDelegate(GetUsersFromService);
   IAsyncResult result = del.BeginInvoke(<somedata>, <somedata>, new AsyncCallback(CallbackMethod), del);
   ...GetUsersFromService(....)
   {
   ...
   }
private void CallbackMethod(IAsyncResult result)
   {
   GDelegate del = (GDelegate)result.AsyncState;
   <somedata> = del.EndInvoke(result);
   gvData.DataSource = <somedata>;
   gvData.DataBind();
   label.Text = "sdfsdf";
   }

This is my code. In CallbackMethod method, I am binding gridview (gvData) and updating a label text. But, gridview and label data are not updating/reflecting in UI. Please let me know how to achieve this. I have searched in google but couldn't get the right answer.

Thanks in advance.
Rams

[edit]Code block added, "Ignore HTML..." option disabled - OriginalGriff[/edit]
Posted
Updated 1-Mar-11 20:47pm
v3
Comments
OriginalGriff 2-Mar-11 2:36am    
Reason for my vote of one: Too impatient to wait...
Member 12272617 7-Mar-16 23:22pm    
HI, Did you find any solution to this. ??

Don't post the same question twice: it has been less than 5 minutes, give people a chance to answer, rather than being so impatient!
 
Share this answer
 
Comments
[no name] 2-Jul-21 0:00am    
Why waste your time being an ASS. If you don't know the answer then just keep scrolling. I can not stand when people reply to these posts like this. How is your response even helpful. Do you get off reading post to just make dumb ass comments. Wow.. What a tough guy... Grow up and either help out or get off the site.
OriginalGriff 2-Jul-21 0:28am    
You waited ten years to be abusive? Good grief, that's an serious grudge you hold there ...
Hi

I answered your question and it got deleted :(

You can't get the response object after the page loaded. So your way won't work.

The concept of Async programing in Asp.Net is different from Win Form. In ASP.net it is used to free http request processing threads, so that concurrent requests can be processed without waiting for a long running background process like a web service contacts.

For example person A request a page which takes long time due to a background processing (contacting the webservice). Like this a few requests consume all the http request processing threads in the pool. So When person B request a page which even don't have any background processing work will have to wait for long time as there is no thread available in the pool to handle it.

For this reason in asp.net has an option Async handling to optimize the performance of the webserver.

Where the http request will be handled through a custom IAsyncHttpHandler implemented class. It has the async methods BeginProcessRequest and EndProcessRequest.

Using that you can intercept the data being send to the response stream and it will free the main thread available for handle next http request.

Otherwise handle the async request using Ajax

Follow the guidelines here...

http://msdn.microsoft.com/en-us/library/ms227433.aspx[^]

http://www.devx.com/asp/Article/29617[^]

Processing Long Running Tasks With Asynchronous Handlers and XMLHTTP[^]

Hope this helps
 
Share this answer
 
Comments
Manfred Rudolf Bihy 2-Mar-11 5:21am    
I'm sorry Albin! My bad, I deleted OP's first post of this question and kept this one as Griff had already posted a response. I must have deleted the question as you were replying. Thanks for replicating your solution here. :)
Manfred Rudolf Bihy 2-Mar-11 5:26am    
Good answer! 5+ (Better than mine anyhow)
Proposed as "the solution".
Albin Abel 2-Mar-11 5:32am    
Hi Manfred not a problem. I used to copy the answer before submit, because I aware sometime internet transmission not successful. So It is not a pain to paste it again. Thank you for your comments.
Manfred Rudolf Bihy 2-Mar-11 6:15am    
Copying ones post before submitting is a good idea Albin.
thatraja 2-Mar-11 10:25am    
Good answer man. 5!
If you're calling a method asynchronously from say your Page_Load method the content of the page may well be returned before the asynchrounous call had a chance to end. If you're after a quickly loading UI you should consider using AJAX. The UI will be presented quickly but the data will be retrieved via AJAX from the browser.

Cheers!
 
Share this answer
 
v2
Comments
Manfred Rudolf Bihy 2-Mar-11 5:22am    
Moved from OP's answer:Hi Manfred,Thanks for the reply.

The gridview is under Ajax Updatepanel control only. But data is not reflecting. Should I do anything else?

ThanksRams

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900