Lets move step by step to get a complete hold on this.
Create an AJAX enabled website
Create an AJAX Enabled web site for this
example. Ajax enabled website is same as normal .net website but having few
more additional tags in web.config.
Add a webservice (MyService.asmx) to the
project. Also add a JS file (Jscript.js) to do the client side activities.
Basically we are going to call the Webmethods present in the websevice through
Add a ScriptManager to the MasterPage with tags as
<asp:ScriptManager ID="ScriptManager1" runat="server">
<asp:ScriptReference Path="JScript.js" />
<asp:ServiceReference Path="MyService.asmx" InlineScript="true" />
Do necessary changes to the webservice
You need to add the ScriptService
attribute to the webservice class. Then add your own webmethod. Here we
have added a GetServerTime() method.
public string GetServerTime()
Test the Webservice, see if it generates the client
After this you should
be able to test whether your webservice is ready to receive calls from the
allow you to download the resulting client proxy. This is possible because of
the presence of Scriptservice Attribute for Webservice class.
If you will save and
open this file, you will find that there will be necessary client proxy entry
for each of the webmethods present in webservice.
The following prompt ensures that
the webservice is correct and ready to use.
Get the result by running the application
After this, create a button and run the following
// JScript File
Here onSuccess and onFailed are the name of the
functions (similar to delegates) that will be executed eventually at the
success and failure of the AJAX Call. The definitions of them are given below.
alert("Current time is: " + result);
alert("Error [" + result._statusCode + "] : " + result._message);
Finally it will look like this: