ASP.NET AJAX

Posted: May 5, 2009 in ajax, asp.net

Microsoft ASP.NET AJAX enables you to call ASP.NET Web services (.asmx files) from the browser by using client script. This enhances the user experience for the Web application. The page can call server-based methods without a postback and without refreshing the whole page, because only data is transferred between the browser and the Web server.

Assign the webservice that needs to be exposed to the script manager.When the script manager receives any service references it will create the javascript needed to access that webservice’s public methods

The following example shows these attributes in Web service code

[System.Web.Script.Services.ScriptService]
public class TournamentMonitor : System.Web.Services.WebService
{

[WebMethod]
public string HelloWorld(int x)
{
return “Hello World”;
}
}

In order for a Web service to be accessed from script, it must be an .asmx Web service whose Web service class is qualified with the ScriptServiceAttribute attribute. Individual methods to be called from script must be qualified with the WebMethodAttribute attribute.
You can also call an WCF file through this method

Javascript Method to access the webservice method
GamePoint.WebApp.WebServices.TournamentMonitor.HelloWorld(param1,onDataAvailable,onFailure,Context)

here you are calling the webservices method HelloWorld() directly from the javascript call

param1-paramenter the method access
onDataAvailable-Callback method .This is the function which will be raised when the call from the webservice returns
onFailure-Function raised if any error occurs
Context-Any javascript object that you need to access in the Callback method(onDataAvailable)

Callback method
function onDataAvailable(result,context,methodName)
{
result-result in the form of JSON returned from the webservice
context- javascript object that was passed from the calling function
methodName -name of the method which raised the callback function
}

For further information
http://www.asp.net/ajax/documentation/l … orial.aspx

Advertisement

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s