在此我用的是 Ajax.NET Professional 可以在下面的地址下载: http://www.codeplex.com/Release/ProjectReleases.aspx?ProjectName=AjaxPro
在下载的压缩文件中,有几个DLL文件,其中AjaxPro.2.dll支持.net framework2.0 ,AjaxPro.dll支持.net framework1.1. 在使用时先将DLL文件引用到项目中.然后在web.config中加入以下内容:
<?
xml version="1.0" encoding="utf-8"
?>
< configuration >
< system .web >
<!-- .net 2.0 -->
< httpHandlers >
< add verb ="POST,GET" path ="ajaxpro/*.ashx" type ="AjaxPro.AjaxHandlerFactory,AjaxPro" />
</ httpHandlers >
<!-- .net1.1 -->
< httpHandlers >
< add verb ="POST,GET" path ="ajaxpro/*.ashx" type ="AjaxPro.AjaxHandlerFactory,AjaxPro.2" />
</ httpHandlers >
</ system.web >
</ configuration >
< configuration >
< system .web >
<!-- .net 2.0 -->
< httpHandlers >
< add verb ="POST,GET" path ="ajaxpro/*.ashx" type ="AjaxPro.AjaxHandlerFactory,AjaxPro" />
</ httpHandlers >
<!-- .net1.1 -->
< httpHandlers >
< add verb ="POST,GET" path ="ajaxpro/*.ashx" type ="AjaxPro.AjaxHandlerFactory,AjaxPro.2" />
</ httpHandlers >
</ system.web >
</ configuration >
namespace
ajax
... {
public class MyForm : System.Web.UI.Page
...{
private void Page_Load(object sender, System.EventArgs e)
...{
AjaxPro.Utility.RegisterTypeForAjax(typeof(MyForm)); //MyForm是这个页定义的类名
}
[AjaxPro.AjaxMethod]
public string TextMethod()
...{
return System.DateTime.Now.ToString("yyyy-MM-dd");
}
}
}
... {
public class MyForm : System.Web.UI.Page
...{
private void Page_Load(object sender, System.EventArgs e)
...{
AjaxPro.Utility.RegisterTypeForAjax(typeof(MyForm)); //MyForm是这个页定义的类名
}
[AjaxPro.AjaxMethod]
public string TextMethod()
...{
return System.DateTime.Now.ToString("yyyy-MM-dd");
}
}
}
//前台javascript代码
function
getTime()
... {
var str=ajax.MyForm.TextMethod().value;
alert(str);
}
... {
var str=ajax.MyForm.TextMethod().value;
alert(str);
}