使用ClientScript.GetCallbackEventReference实现局部刷新是.NET支持的一种前后台代码调用的方式;其实实现局部刷新这样方式有很多种,最经典也常用的莫过于jQuery封装好的异步调用方法(Ajax, get, getJSON, post),这里就不去多加比较,毕竟都会接触到。
下面是简单的例子:
页面前台关键代码:
1//删除投诉信息2functionf_DeleteComplaint() {3varcurrentKey =gridManager.GetSelectRowKeyValue();4if(currentKey !=null) {5if(confirm('<%=Strings.GetString("Sdelete")%>')) {6vardeleteInfo = "Complaint" + deleteSign +currentKey;7<%=ClientScript.GetCallbackEventReference(this, "deleteInfo", "refresh", "")%>;8}9}10else{11alert('<%=Strings.GetString("S1044") %>!');12}13}14functionrefresh(val) {15switch(val.toLowerCase()){16case"complaint":17gridManager.Refresh(0);18
break;19}20}
页面后台关键代码:
usingSystem;usingSystem.Collections.Generic;usingSystem.Data;usingSystem.Linq;usingSystem.Web;usingSystem.Web.UI;usingSystem.Web.UI.WebControls;publicpartialclassPSWholeSale_PSWholeSaleEdit : System.Web.UI.Page, ICallbackEventHandler
{publicstringreturnValue ="ok";PRotectedchardeleteSign ='|';#regionICallbackEventHandler 成员publicstringGetCallbackResult()
{returnreturnValue;
}publicvoidRaiseCallbackEvent(stringdeleteInfo)
{string[] deleteInfoArr =deleteInfo.Split(deleteSign);if(deleteInfoArr.Length >1)
{stringsql ="";
returnValue= deleteInfoArr[0];switch(deleteInfoArr[0].ToLower())
{case"complaint":
sql="update PS_Complaint set RecordStatus='Inactive' where ComplaintID=@id";
break;
}if(!string.IsNullOrEmpty(sql))
{
DataaccessHelper.ExecuteNonQuery(sql,newDbParameterHelper("id", DbType.Int32, deleteInfoArr[1]));
}
}
}#endregion}