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>
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); // This _ default refers to the Class Name of the page class. If it is placed in a namespace, you need to 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 ajaxpro can call for shadow. [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 = "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";} // This method allows the user to accept and process 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 ajaxpro. DLL and Ajax. the two DLL versions are similar, but there are still differences. The main differences are as follows: (1) web. the Config configuration file is different from that of Ajax. the DLL configuration file is written as <add verb = "post, get" Path = "ajax /*. ashx "type =" Ajax. pagehandlerfactory, Ajax "/> ajaxpro. the DLL configuration file is written as <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 );
------------------------------------------------------------
I have been using ajaxpro for Ajax-related functions, but I encountered a problem during the previous two days. Each call prompts the JS error "XXX undefined ", I checked and found that ajaxpro did not output the corresponding method definition to the client. Finally, I compared it with the previous page at, and finally found that: the <form runat = "server"> flag is missing on the page. After the tag is added, everything works properly :-)
More and more JS applications, fewer and fewer front-end Asp.net tags, and even <form runat = "server"> are useless ······
Reposted on Netease. Thanks for your originality. This is a good solution to the problem.Article!