首先下载ajaxpro.dll,你可以从http://www.ajaxpro.info/获得。最新版本是7.7.31.1,下载解压后的文件夹中有个AjaxPro.dll,就是它了。使用VS2008新建web项目,并添加对AjaxPro.dll的引用,然后在Web配置文件中添加:

<httpHandlers>
<add verb="POST,GET" path="ajaxpro/*.ashx" type="AjaxPro.AjaxHandlerFactory, AjaxPro"/>
</httpHandlers> 这个配置项表明所有的ajaxpro/*.ashx请求(即从客户发送的Ajax请求)都交给AjaxPro.AjaxHandlerFactory处理,而不是由默认的System.Web.UI.PageHandlerFactory来处理。
我这里是新建的测试页面test6
1
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="test6.aspx.cs" Inherits="test6" %>
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
<head id="Head1" runat="server">
6
<title></title>
7
8
<script type="text/javascript">
9
function getID(id) {
10
return document.getElementById(id);
11
}
12
13
//无刷新返回当前时间
14
function Time() {
15
getID("str1").innerHTML = Main.getTime().value;
16
}
17
</script>
18
19
</head>
20
<body>
21
<form id="form1" runat="server">
22
<div>
23
<input id="Button1" type="button" value="无刷新返回当前时间" onclick="Time()" />
24
<span id="str1" />
25
</div>
26
</form>
27
</body>
28
</html>
29

1
using System;
2
using System.Collections;
3
using System.Configuration;
4
using System.Data;
5
using System.Web;
6
using System.Web.Security;
7
using System.Web.UI;
8
using System.Web.UI.HtmlControls;
9
using System.Web.UI.WebControls;
10
using System.Web.UI.WebControls.WebParts;
11
12
[AjaxPro.AjaxNamespace("Main")]
13
public partial class test6 : System.Web.UI.Page
14
{
15
protected void Page_Load(object sender, EventArgs e)
16
{
17
//注册本页为AJAX
18
AjaxPro.Utility.RegisterTypeForAjax(typeof(test6));
19
}
20
21
//无刷新返回当前时间
22
[AjaxPro.AjaxMethod]
23
public string getTime()
24
{
25
string Time = "<font color='green'>" + DateTime.Now.ToString() + "</font>";
26
return Time;
27
}
28
}
29

<httpHandlers>
<add verb="POST,GET" path="ajaxpro/*.ashx" type="AjaxPro.AjaxHandlerFactory, AjaxPro"/>
</httpHandlers>
我这里是新建的测试页面test6

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29


1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29
