2):在web.config配置
<system.web>
<httpHandlers>
<add verb="POST,GET" path="ajaxPro/*.ashx" type="AjaxPro.AjaxHandlerFactory, AjaxPro" />
</httpHandlers>
3)后台codebehind cs:
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using AjaxPro;
namespace ajax
{
/// <summary>
/// WebForm1 的摘要说明。
/// </summary>
public class WebForm1 : System.Web.UI.Page
{
protected System.Web.UI.WebControls.TextBox TextBox1;
protected System.Web.UI.WebControls.Label Label1;
private void Page_Load(object sender, System.EventArgs e)
{
//注册
AjaxPro.Utility.RegisterTypeForAjax(typeof(WebForm1));
}
//方法
[AjaxPro.AjaxMethod()]
public string TestMehtod(string name)
{
return this.BuildMessage(name);
}
protected string BuildMessage(string name)
{
return string.Format("Hello{0}!welcome to ajaxpro's world",name);
}
4)前台页面html
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
<HEAD>
<title>WebForm1</title>
<meta name="GENERATOR" Content="Microsoft Visual Studio .NET 7.1">
<meta name="CODE_LANGUAGE" Content="C#">
<meta name="vs_defaultClientScript" content="JavaScript">
<meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5">
<script language="javascript" type="text/javascript">
function TF()
{
var sm=ajax.WebForm1.TestMehtod("zqf");
return sm.value;
}
</script>
</HEAD>
<body>
<form id="Form1" method="post" runat="server">
<FONT face="宋体">
<asp:TextBox id="TextBox1" runat="server"></asp:TextBox>
<asp:Label id="Label1" runat="server" Width="88px">Label</asp:Label></FONT>
</form>
<script language="javascript">
document.write(TF());
</script>
</body>
</HTML>