Monday, March 26, 2012

Updating a website with data from an asynchronously called Webservice

Hi!

I wrote the following code to update a label on my aspx-page with data retrieved by an asynchronously called Webservice.

Protected Sub Page_Load(ByVal senderAs Object,ByVal eAs System.EventArgs)Handles Me.LoadIf Not Page.IsPostBackThen Dim wsAs localhost.WebServiceTest =New localhost.WebServiceTestDim ResultAs IAsyncResult = ws.Beginmessages(AddressOf renderResult, ws)End If End Sub Private Sub renderResult(ByVal ResultAs IAsyncResult)Dim wsAs localhost.WebServiceTest =CType(Result.AsyncState, localhost.WebServiceTest) Label1.Text = ws.Endmessages(Result)End Sub

The problem is that the Label (which is surrounded by an Updatepanel) does not get updated with the value returned by the Webservice although "renderResult" is executed correctly. (Maybe the problem is that the asynchronous function is called in a different thread on the webserver?)

Do you have any ideas or solutions to solve this issue?

Thank you

No suggestions?


Try doing your asynchronous webservice calls from the client-side rather than from the server.

http://www.asp.net/learn/ajax-videos/video-79.aspx

http://www.asp.net/AJAX/Documentation/Live/tutorials/ASPNETAJAXWebServicesTutorials.aspx


As DisturbedBuddha points out, you would probably want to do this sort of thing client side (remember the runat=server thing).

But, if youreally want to do this server side, my first question would be - is the updatepanel inside a form?

Cheers

Martin


Thank you for your help.

Calling the webservice client-side worked!

No comments:

Post a Comment