AjaxPro.Net是一个优秀的.net环境下的ajax框架
.net 2.0对应的DLL为AjaxPro.2.dll,这个网上提供下载的地址很多。
一 环境
Windows 2003
VS 2005
AjaxPro 2
二 例子
1) 新建ASP.NET工程
2) 添加AjaxPro.2.dll
3) 修改WEB.CONFIG
4)新建一个页面ajaxpro.aspx,代码:
<%
@ Page Language
=
"
C#
"
AutoEventWireup
=
"
true
"
CodeFile
=
"
ajaxpro.aspx.cs
"
Inherits
=
"
ajaxpro
"
%>

<!
DOCTYPE html PUBLIC
"
-//W3C//DTD XHTML 1.0 Transitional//EN
"
"
http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd
"
>
<
html xmlns
=
"
http://www.w3.org/1999/xhtml
"
>
<
head id
=
"
Head1
"
runat
=
"
server
"
>
<
title
>
AjaxPro onLoading
</
title
>
</
head
>
<
body
>
<
form id
=
"
form1
"
runat
=
"
server
"
>
<
div id
=
"
loadinfo
"
style
=
"
visibility:hidden;position:absolute;left:0px;top:0px;background-color:Red;color:White;
"
>
Loading
</
div
>
<
input id
=
"
Button1
"
type
=
"
button
"
value
=
"
Get ServerTime
"
onclick
=
"
javascript:GetTime();void(0)
"
/>

<
script type
=
"
text/javascript
"
defer
=
"
defer
"
>
//
loading效果
AjaxPro.onLoading
=
function(b) 
...
{
var a = document.getElementById("loadinfo");
a.style.visibility = b ? "visible" : "hidden";
}

function GetTime() 
...
{
// 调用服务端方法
//调用方法:类名.方法名 (参数为指定一个回调函数)
ajaxpro.GetServerTime(callback);
}

function callback(res)
//
回调函数,显示结果

...
{
alert(res.value);
}
</
script
>
</
form
>
</
body
>
</
html
>
5) 后台代码:
using
System;
using
System.Data;
using
System.Configuration;
using
System.Collections;
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;
using
AjaxPro;
public
partial
class
ajaxpro : System.Web.UI.Page
...
{
protected void Page_Load(object sender, EventArgs e)
...{
AjaxPro.Utility.RegisterTypeForAjax(typeof(ajaxpro)); //注册ajaxPro,括号中的参数是当前的类名
}
[AjaxPro.AjaxMethod] //申明是ajaxPro方法
public string GetServerTime()
...{
System.Threading.Thread.Sleep(2000);
return DateTime.Now.ToString();
}
}
三 测试
http://localhost:1966/WebSite2/ajaxpro.aspx
参考:
http://www.cnblogs.com/chy710/archive/2007/04/18/718715.html
<
httpHandlers
>
<
add verb
=
"
POST,GET
"
path
=
"
ajaxpro/*.ashx
"
type
=
"
AjaxPro.AjaxHandlerFactory, AjaxPro
"
/>
</
httpHandlers
>
本文介绍了一个.NET环境下的Ajax框架——AjaxPro.NET,并通过一个实例展示了如何使用AjaxPro.NET实现异步加载效果。该实例包括了前端页面设计及后端代码实现。
8650





