1. First introduce ajaxpro.2.dll into the project
2. Add the following nodes in the Web.config file <system.web> node < httphandlers >
< add verb = "*" Path = "*.ashx" type = "Ajaxpro.ajaxhandlerfactory,ajaxpro.2"/>
Server-side page code public partial class _default:system.web.ui.page
... {
protected void Page_Load (object sender, EventArgs e)
... {
Registering AJAX Classes
AjaxPro.Utility.RegisterTypeForAjax (typeof (_default));
}
[Ajaxpro.ajaxmethod]//Duanfang Add (Ajaxmethod) attribute to the server to be invoked
public string Welcome (string name)
... {
Return "Hello" + name;
}
Client code: <% ... @ Page language= "C #" autoeventwireup= "true" codefile= "Default.aspx.cs" inherits= "_default"%>
<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en"
"Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" >
< html xmlns = "http://www.w3.org/1999/xhtml" >
< head runat = "server" >
< title > Welcome </title >
< script type = "Text/javascript" > ...
function Callservermethod ()
... {
Get the value in the text box
var Name=document.getelementbyid ("Text1"). Value;
Call the server-side method and indicate the handler function
_default.welcome (Name,callback);
}
Function callback (RES)
... {
The Div object that gets the display information
var Odiv=document.getelementbyid ("Welcomemsg");
Specify the text returned from the server for the innerHTML property of the Div object
Odiv.innerhtml=res.value;
}
</script >
< BODY >
< form ID = "Form1" runat = "server" >
< div >
< input ID = "TEXT1" type = "Text"/>
< input ID = "Button1" type = "button" value = "OK" onclick = "callservermethod ();"/></div >
< div id = "welcomemsg" ></div >
</form >
</Body >
</HTML >
Such a simple AJAX application is done.