我在写代码时,太马虎 。在客户端少写了.value。真晕
我做了一个超简单的 AjaxProDemo ,发上来供初学者用!!!
步骤如下:
1. 添加 AjaxPro.dll 文件的引用(示例代码中已经包含,直接COPY过来使用即可).
2. 在Web.config文件中添加以下配置,
<httpHandlers> <add verb="POST,GET" path="ajaxpro/*.ashx" type="AjaxPro.AjaxHandlerFactory, AjaxPro" />
</httpHandlers>
</httpHandlers>
3. 在要使用AjaxPro.NET框架的页面 *.aspx.cs 的 Page_Load事件中加如下代码:
AjaxPro.Utility.RegisterTypeForAjax(typeof(_Default));
4. 经过以上三步骤后, 只要在后台服务端的方法前面增加属性[AjaxMethod]后:
[AjaxMethod()] // or [AjaxPro.AjaxMethod]
public string GetString( string val)
{
return val;
}
public string GetString( string val)
{
return val;
}
就可以在客户端直接使用服务端方法, 非常方便, 客户端调用后台代码如下:

具体如下:
web.config文件
<?xml version="1.0"?>
<configuration>
<appSettings/>
<connectionStrings/>
<system.web>
<httpHandlers>
<add verb="POST,GET" path="ajaxpro/*.ashx" type="AjaxPro.AjaxHandlerFactory, AjaxPro" />
</httpHandlers>
<compilation debug="true"/>
<authentication mode="Windows"/>
</system.web>
</configuration>
<configuration>
<appSettings/>
<connectionStrings/>
<system.web>
<httpHandlers>
<add verb="POST,GET" path="ajaxpro/*.ashx" type="AjaxPro.AjaxHandlerFactory, AjaxPro" />
</httpHandlers>
<compilation debug="true"/>
<authentication mode="Windows"/>
</system.web>
</configuration>
Default.aspx文件:
























Default.aspx.cs文件:
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 _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
Utility.RegisterTypeForAjax(typeof(_Default) );
TextBox1.Attributes.Add("onblur", "A(this.value);");
}
[AjaxPro.AjaxMethod]
public string GetString(string val)
{
return val;
}
}
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 _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
Utility.RegisterTypeForAjax(typeof(_Default) );
TextBox1.Attributes.Add("onblur", "A(this.value);");
}
[AjaxPro.AjaxMethod]
public string GetString(string val)
{
return val;
}
}
记得要引用AjaxPro.dll文件!!