views:

361

answers:

2

Hi all,

I need to call a webmethod of a webservice asynchronously from code behind of a web page. In the callback function I need to bind a gridview and render it. I want to partially render that gridview in the callback function in codebehind.

How to implement that?

Is it possible to implement all these in codebehind without using javascript?

A: 

You can use ASP.NET asynchronous page load for that.

In general, it consists of adding Async="true" to the page directive and adding some event handlers in the code behind.

Great resource about this subject is the "Asynchronous Pages in ASP.NET 2.0" MSDN Magazine article.

Shay Friedman
+2  A: 

There are a couple of options, but basically you need to do something like this:

  1. Use Visual Studio to build a proxy class to access the web service, using the published WSDL
  2. Create an async web page, by setting Async=True in the Page directive
  3. In the Page_Load() method of your code behind, register methods that will start and end the async web service call by creating a PageAsyncTask object and calling RegisterAsyncTask()
  4. From the method that starts the async task, call the Begin method that was created as part of the proxy class, and return the associated IAsyncResult to the caller
  5. When the web service call completes, the runtime will call your registered end method. From there, call the End method in the proxy to get the results of the call.
  6. Databind the results to a GridView on your page.

In case it helps, I walk through a detailed example along these lines in my book, including sample code: Ultra-Fast ASP.NET.

RickNZ