AjaxPro对于Web服务端不对表单元素进行操作的调用。
1、引用AjaxPro.dll文件
2、保证客户端向"*.ashx"的请求(POST和GET)都被AjaxPro.AjaxHandlerFactory拦截。
打开web.config文件,在<configuration><system.web>后添加以下代码
<httpHandlers>
<add verb="*" path="*.ashx" type="AjaxPro.AjaxHandlerFactory,AjaxPro.2"/>
</httpHandlers>
前台Default.aspx
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<script language="javascript" type="text/javascript">
function comit_onclick()
{
var name = document.getElementById("tb1").value;
var callback = document.getElementById("tb").value;
var parameters = Defaults.SetTb(name, callback).value;
if (parameters=="1"){
alert("你未填写!"); document.getElementById("lk_update").click();
}
else {
alert("你已填写!");
}
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:TextBox ID="tb1" runat="server"></asp:TextBox><br />
<asp:TextBox ID="tb" runat="server"></asp:TextBox><br />
<input id="comit" type="button" value="Ok" onclick="return comit_onclick()" /></div>
</form>
</body>
</html>
后台.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
[AjaxPro.AjaxNamespace("Defaults")]
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
AjaxPro.Utility.RegisterTypeForAjax(typeof(_Default));
}
[AjaxPro.AjaxMethod]
public string SetTb(string Name, string Callback)
{
string message = "0";
if (Name == "" && Callback == "")
{
message = "1";
}
return message;
}
}
3、在后台.CS类前添加 [AjaxPro.AjaxNamespace("所在类类名")],这里可以自由取名,一般方便识别取用该类类名
4、在Page_Load方法体内加上如下代码:AjaxPro.Utility.RegisterTypeForAjax(typeof(所在类类名));
5、每个AjaxPro方法前必须添加 [AjaxPro.AjaxMethod]
6、如果方法内需要Session [WebMethod(EnableSession=true)]
7、如果方法内有可读写程序 [AjaxPro.AjaxMethod(AjaxPro.HttpSessionStateRequirement.ReadWrite)]
浙公网安备 33010602011771号