1. WebServices. aspx <% @ Page Language = " C # " Autoeventwireup = " True " Codefile = " WebServices. aspx. CS " Inherits = " Webservicestest " %>
< Html Xmlns = "Http://www.w3.org/1999/xhtml" >
< Head Runat = "Server" >
< Title > Ajaxwebservicetest </ Title >
</ Head >
< Body >
< Form ID = "Form1" Runat = "Server" >
< ASP: scriptmanager ID = "Scriptmanager1" Runat = "Server" >
< Services >
< ASP: servicereference Path = "../WebService/ajaxservice. asmx" />
</ Services >
</ ASP: scriptmanager >
< ASP: updateprogress ID = "Updateprogress1" Runat = "Server" >
< Progresstemplate >
< IMG SRC = "../Images/loading.gif" />
Loading
</ Progresstemplate >
</ ASP: updateprogress >
< Div >
< Input ID = "Inputname" Type = "Text" Size = "20" Runat = "Server" />
< Input ID = "Btntest" Type = "Button" Value = "Call" Onclick = "Return btntest_click ()" />
</ Div >
</ Form >
</ Body >
</ Html >
< Script Type = "Text/JavaScript" Language = "JavaScript" >
Function $ (S) {ReturnDocument. getelementbyid (s );}
Function Btntest_click ()
{
VaR Requestsimpleservice = Ajaxservice. ajaxservicetest (
$ (' <% = Inputname. clientid %> '). Value, // Params
Onrequestcomplete // Complete Event
);
Return False ;
}
Function Onrequestcomplete (result)
{
Alert (result );
}
</ Script >
2. ajaxservice. asmx <% @ WebService
Language = " C # "
Codebehind = " ~ /App_code/WebService/ajaxservice. CS "
Class = " Ajaxservice " %>
3. ajaxservice. CS Using System;
Using System. Web. Services;
Using System. Web. Script. Services; // *** Required
[Scriptservice]
Public Class Ajaxservice: WebService
{
Public Ajaxservice ()
{}
[Webmethod]
Public String Ajaxservicetest ( String S)
{
Framework. appexception. logfile (s );
Return "Hello" +S;
}
}