1. first put Ajax. DLL to add reference to the project, right-click on the project, there is a [add reference] on the menu, and then step by step that. after adding the DLL file, you will see the Ajax in the reference of the project. DLL is successfully added.
2. modify web. config. Add the following code to the <system. Web> element. The Ajax. dll and ajaxpro. dll reference methods here are different. Be sure to pay attention to them.
<Configuration>
<System. Web>
<Httphandlers>
<! -- The configuration file of Ajax. dll is written as, which is the one I downloaded -->
<Add verb = "post, get" Path = "ajax/*. ashx" type = "Ajax. pagehandlerfactory, Ajax"/>
<! -- The configuration file of ajaxpro. dll is written as: select different configuration statements based on the DLL file you downloaded -->
<Add verb = "*" Path = "ajaxpro/*. ashx" type = "ajaxpro. ajaxhandlerfactory, ajaxpro"/>
</Httphandlers>
</System. Web>
</Configuration>
3. register the page page_load event used by ajaxpro during runtime. For example:
Protected void page_load (Object sender, eventargs E)
{
Ajax. Utility. registertypeforajax (typeof (_ default); // Ajax. dll
Ajaxpro. Utility. registertypeforajax (typeof (_ default); // ajaxpro. dll
}
// This _ default refers to the Class Name of the page class, which is the name of the page. If it is placed in a namespace, you must enter the complete namespace (for example, namespaces. _ default)
4. Create a server
[Ajax. ajaxmethod] // This sentence must exist. If you are ajaxpro. dll, write it as [ajaxpro. ajaxmethod].
Public String getvalue (int A, int B)
{
// This method transfers two numbers from the client and returns them to the client after adding them to the server. You can write a class in the background of the original page.
Return convert. tostring (a + B); // The value returned here is the value obtained at the front end. The parameter is already included in the CS file. You can perform the operation as needed, including reading the database.
}
5. Client call.
<% @ Page Language = "C #" codebehind = "webpage1.aspx. cs" autoeventwireup = "false" inherits = "Web. webpage1" %>
<Script language = "JavaScript">
Function getvalue ()
{
// If it is ajaxpro. dll, add web. _ default. getvalue. If it is Ajax. dll, you do not need to add the following namespace:
_ Default. getvalue (, getgroups_callback); // call the _ default. getvalue method on the server.
// _ Default is the class that writes getvalue. If it is written in Cs on this page, webpage1.getvalue, 1 and 2 are parameters.
// Getgroups_callback specifies a callback function to receive the client result after the server completes processing.
}
// The user accepts and processes the results returned by the server.
Function getgroups_callback (response)
{
VaR dt = response. value; // The value is the value that is finally passed back. Use it whenever you want. Return to the front-end anyway.
Document. getelementbyid ("div_1"). innerhtml = DT;
}
</SCRIPT>
<Body>
<Div id = "div_1"> </div>
<Button onclick = getvalue ()> Start </botton>
</Body>
From: http://www.cnblogs.com/yugen/archive/2010/08/03/1791563.html
This article from the csdn blog, reproduced please indicate the source: http://blog.csdn.net/li_shengwangso/archive/2011/04/19/6334234.aspx