Ajax. net Professional
Microsoft. NET Framework 2.0
About ajax.net professional:
Ajax.net is a server framework for. NET platform Ajax.(Microsoft also has a framework called ATLAS. For details about Atlas, see dflying Chen's blog ),It allows you to call the. NET method on the client, and you can also obtain the relevant source code. However, its license agreement is not very clear.
Contact Author: http://weblogs.asp.net/mschwarz/contact.aspx
Original Author's blog: http://weblogs.asp.net/mschwarz/
If you have any problem or find a bug, visit: Google group Ajax. Net professional.
Original email address:
Michael Schwarz
Meisenweg 2
90547 Stein, Germany
Download Ajax. Net Pro (5.11.4.2), including for. net1.1 (C #) and. net2.0 (C #/VB. NET ).
Let's start from here: Ajax. Net beginner Guide
First, add a reference to ajaxpro.2.dll (add ajaxpro. DLL to. NET Framework 1.1)
Then, add the configuration file web. config and add the following lines:
1 <? XML version = "1.0" encoding = "UTF-8"?>
2 <configuration>
3 <appsettings/>
4 <connectionstrings/>
5 <system. Web>
6 7 <add verb = "post, get" Path = "ajaxpro/*. ashx" type = "ajaxpro. ajaxhandlerfactory, ajaxpro.2"/>
8 9 []
10 </system. Web>
11 </configuration>
12
This means that all ajaxpro/*. ashx requests are handled by Ajax. pagehandlerfactory, rather than by the default system. Web. UI. pagehandlerfactory handler factory.
Now let's write an ajaxmethod server method. The only difference between it and the common server method is that it must add a [ajaxpro. ajaxmethod] on the method. The Code is as follows:
1 [ajaxpro. ajaxmethod]
2 Public int addtwo (INT firstint, int secondint)
3 {
4 return firstint + secondint;
5}
To use JavaScript to call. Net methods on the client, you must register these methods:
1 protected void page_load (Object sender, eventargs E)
2 {
3 ajaxpro. Utility. registertypeforajax (typeof (_ default ));
4}
Finally, we will write the client script to call the server method (The Code contains detailed comments ).
The front-end default. aspx code is as follows:
1 <% @ page Language = "C #" autoeventwireup = "true" codefile = "default. aspx. cs" inherits = "_ default" %>
2
3 <! Doctype HTML public "-// W3C // dtd xhtml 1.0 transitional // en" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
4 <HTML xmlns = "http://www.w3.org/1999/xhtml">
5 6 <title> untitled page </title>
7 8 <body>
9 <Form ID = "form1" runat = "server">
10 <div>
11 <input id = "text1" type = "text" onchange = "add ()"/>
12 +
13 <input id = "text2" type = "text" onchange = "add ()"/>
14 =
15 <span id = "result"> </span>
16 </div>
17 </form>
18
19 <SCRIPT type = "text/JavaScript">
20 function add ()
21 {
22 var A = Document. getelementbyid ('text1'). value;
23 var B = Document. getelementbyid ('text2'). value;
24 var a1 = parseint ();
25 var b1 = parseint (B );
26
27 _ default. addtwo (A1, B1, getadd_callback); // asynchronously calls the server Method
28}
29
30 function getadd_callback (rel)
31 {
32 // mydemo. _ default. getservertime (). The data sent from the server is an object, which must be written as. value.
33 document. getelementbyid ("result"). innerhtml = Rel. value;
34}
35
36 </SCRIPT>
37
38 </body>
39 40
The complete background default. aspx. CS code is as follows:
Using system;
Using system. Data;
Using system. configuration;
Using system. Web;
Using system. Web. Security;
Using system. Web. UI;
Using system. Web. UI. webcontrols;
Using system. Web. UI. webcontrols. webparts;
Using system. Web. UI. htmlcontrols;
Public partial class _ default: system. Web. UI. Page
{
[Ajaxpro. ajaxmethod]
Public int addtwo (INT firstint, int secondint)
{
Return firstint + secondint;
}
Protected void page_load (Object sender, eventargs E)
{
Ajaxpro. Utility. registertypeforajax (typeof (_ default ));
}
}