This example demonstrates one of many possible scenarios when a client should be notified of the progress of a server process. Web methods allow you to make a request from the client and return information that can be restored and used to display a current progress, without refreshing the whole page.
The sample demonstrates how to use web methods in two ways:
- Using the jQuery library (the jQuery.aspx page);
- Using ScriptManager (the ScriptManager.aspx page);
Note that web methods should have the [WebMethod] attribute (WebMethod(EnableSession = true) if you use the session). They are defined in the BasePage class that is used by both the jQuery and ScriptManager pages.
To call a web method using jQuery, perform a POST request to the method:
[JScript]WebMethodRequest("jQuery.aspx/StartOperation");...function WebMethodRequest(url, callback){ $.ajax({ url: url, type: "POST", contentType: 'application/json; charset=utf-8', success: callback});}
In case you use ScriptManager, the syntax would be as follows:
[JScript]PageMethods.StartOperation();
Please refer to the following links to know more:
Exposing Web Services to Client Script
How to call WebMethod?
This example extends the following one: How to display progress information about server-side callback processing.
See also:
How to track progress of server side processing on the client side (using HttpModule)
How to track progress of server side processing on the client side (using HttpHandler)