AjaxPro局部刷新完整例子
第一步:添加AjaxPro.dll,并且引用dll
第二步:配置Web.config
1 <system.webServer> 2 <handlers> 3 <add name="ajaxpro" verb="POST,GET" path="ajaxpro/*.ashx" type="AjaxPro.AjaxHandlerFactory,AjaxPro"/> 4 </handlers> 5 </system.webServer>
第三步:Debault.aspx.cs里引入
protected void Page_Load(object sender, EventArgs e) { AjaxPro.Utility.RegisterTypeForAjax(typeof(ShareMaintenace)); if (!IsPostBack) { BindData(0); } }
第四步:Debault.aspx页面
function prompt(obj) { var str = $(obj).val(); if (str.trim() == "" || event.keyCode == 13) { $("#prompt").hide(); $("#prompt").html(""); } //调用后台方法,局部刷新技术 var str = Lcp.Share.Admin.Web.ShareMaintenace.GetAllShareList(str).value; if(str == "") { $("#prompt").hide(); return; } $("#prompt").html(str); $("#prompt").show(); setMouseEvent(); }
第五步:Debault.aspx.cs写入方法
//一定要引用 [AjaxPro.AjaxMethod] public string GetAllShareList(string shares) { string share = shares; string shareMsg = ""; if (!string.IsNullOrEmpty(share)) { IShareService service = Kernel.GetService<IShareService>(); ShareDataGetResponse scp = service.GetShareDataGetResponse(share); scp.ShareDataList.ForEach(o => { //shareMsg += "<li>" + o.ShareCode + " " + o.ShareName + "</li>"; shareMsg += "<a class='hide_share' style='display:block;' href='javascript:void(0);' onclick=\"fullShareName('" + o.ShareName + "')\">" + o.ShareCode + " " + o.ShareName + "</a> "; }); } return shareMsg; }