1. There are direct frameworks: ajaxpro and Ajax. I have used these two types and I think they are good.
2. there is also a control package specially developed for Ajax by Microsoft, called ASP. net Ajax Control Toolkit. I have not studied it too much. I have related information on the Internet. If you want to know it, you can check it by yourself. There are many ready-made controls that can implement Ajax.
The above three methods are some of the Ajax implementation methods I have collected. I want to talk about the application of the first method, because the first method can help you understand the running principle of Ajax and is suitable for beginners.
I mainly talk about ajaxpro, which is a component and must be downloaded online. It is actually an ajaxpro. DLL files. Note that there are two types of files called Ajax on the Internet. DLL is called ajaxpro. DLL, the two functions are the same, that is, the statements for adding references are somewhat different. I will explain them separately below. In fact, Ajax requires related components. At first, I am not used to any plug-ins, but later I went down. I went down to Ajax. dll, so Ajax. dll prevails.
Application, the following things will be used by others on the InternetArticle, Declare it here
1. first put Ajax. DLL is added to the project. Don't tell me I won't. If this is the case, right-click the project and choose [add reference] from the menu. then, step by step. 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 to the <system. Web> element:Code. 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>
For iis7. webserver> </system. add <Add name = "ajax" verb = "post, get" Path = "ajax/* To webserver> /*. ashx "type =" Ajax. pagehandlerfactory, Ajax "/>
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 "%>
// If it is ajaxpor. 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 </botton>
</Body>