1. First download the ajaxpro component. And reference ajaxpro. DLL to the website (or project ).
2. modify web. config. In<System. Web>Add the followingCode.
<Configuration>
<System. Web>
<Httphandlers>
<! -- Register the Ajax Handler -->
<Add verb = "*" Path = "ajaxpro/*. ashx" type = "ajaxpro. ajaxhandlerfactory, ajaxpro"/>
</Httphandlers>
</System. Web>
</Configuration>
3. Register ajaxpro during the page_load event on the page. For example:
Protected void page_load (Object sender, eventargs E)
{
Ajaxpro. Utility. registertypeforajax (typeof (_ default); // The _ default parameter indicates the page.
Class Name. If it is placed in a namespace, you must enter the complete namespace (for example, namespaces. _ default)
}
4. Create a server method. If you add the [ajaxpro. ajaxmethod] tag to a method,
the method becomes a method that can be called by ajaxpro for shadow.
[ajaxpro. ajaxmethod]
Public String getvalue (int A, int B)
{< br> // This method is used to input two numbers from the client, return to the client after adding computing on the server side.
return convert. tostring (a + B);
}
5. Client call.
<Script language = "JavaScript">
Function getvalue (){
_ Default. getvalue (, getgroups_callback); // call the _ default. getvalue method on the server.
This requires a callback function to receive the client result after the server completes processing.
Form1.textbox1. value = "123 ";
}
// The user accepts and processes the results returned by the server.
Function getgroups_callback (response ){
VaR dt = response. value;
Alert (DT );
}
</SCRIPT>
This is simple, but it is already a complete ajaxpro.
Of course, ajaxpro can provide many more practical and powerful functions. This is just an example. Sort the other files in another day and try again.
Please note that ajax.net actually has two versions: ajaxpro. dll and Ajax. dll. These two versions are similar in use, but there are still differences. The main differences are as follows:
(1) The web. config configuration file is different.
The configuration file of Ajax. dll is written
<Add verb = "post, get" Path = "ajax/*. ashx" type = "Ajax. pagehandlerfactory, Ajax"/>
The configuration file of ajaxpro. dll is written
<Add verb = "*" Path = "ajaxpro/*. ashx" type = "ajaxpro. ajaxhandlerfactory, ajaxpro"/>
(2) the method for calling server methods is different. Many friends find that the namespace cannot be found or the object is not defined.
When referencing Ajax. dll, do not add a namespace when calling the server method,
When ajaxpro. dll is applied, a namespace is required to call the server method.
For example, when the page is set to this setting
<% @ Page Language = "C #" codebehind = "test. aspx. cs" autoeventwireup = "false" inherits = "Web. Test" %>
Client call Method
Ajax. dll is
VaR response = test. getservermethod ();
Alert (response. value );
Ajaxpro. dll is
VaR response = web. Test. getservermethod ();
Alert (response. value );
In addition, ajaxpro's latest official test version will encounter a null pointer error when generating the client script, so please do not try this version, try to use a stable version as much as possible