Application of ASP. NET ajaxpro
1. First download the ajaxpro component. And reference ajaxpro. DLL to the website (or project ).
2. modify web. config. Add the following to the <system. Web> element:Code.
<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. Add the [ajaxpro. ajaxmethod] tag to a method,
This method becomes a method that ajaxpro can call for shadow. As follows:
[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.
Return convert. tostring (A + B );
}
5. Client call.
<Script language = "javasOther ">
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.
The two are different:
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. For this reason, many friends find that the namespace cannot be found or the object does not reference Ajax. when calling a DLL, do not add a namespace to the server method. Apply ajaxpro. when calling a DLL, you need to add a namespace 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 );
Slave --------------------------------------------------------------------------------------------------------------------------------
<Add verb = "*" Path = "ajaxpro/*. ashx" type = "ajaxpro. ajaxhandlerfactory, ajaxpro"/>
<Remove verb = "*" Path = "*. asmx"/>
<Add verb = "*" Path = "*. asmx" type = "ajaxpro. ajaxhandlerfactory, ajaxpro"/>