使用ClientScript.GetCallbackEventReference实现局部刷新是.NET支持的一种前后台代码调用的方式;其实实现局部刷新这样方式有很多种,最经典也常用的莫过于jQuery封装好的异步调用方法(ajax, get, getJSON, post),这里就不去多加比较,毕竟都会接触到。
下面是简单的例子:
页面前台关键代码:
//删除投诉信息
function f_DeleteComplaint() {
var currentKey = gridManager.GetSelectRowKeyValue();
if (currentKey != null) {
if (confirm('<%=Strings.GetString("Sdelete")%>')) {
var deleteInfo = "Complaint" + deleteSign + currentKey;
<%=ClientScript.GetCallbackEventReference(this, "deleteInfo", "refresh", "")%>;
}
}
else {
alert('<%=Strings.GetString("S1044") %>!');
}
}
function refresh(val) {
switch(val.toLowerCase()){
case "complaint":
gridManager.Refresh(0);
break;
}
}
页面后台关键代码:
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls; public partial class PSWholeSale_PSWholeSaleEdit : System.Web.UI.Page, ICallbackEventHandler
{
public string returnValue = "ok";
protected char deleteSign = '|'; #region ICallbackEventHandler 成员
public string GetCallbackResult()
{
return returnValue;
} public void RaiseCallbackEvent(string deleteInfo)
{
string[] deleteInfoArr = deleteInfo.Split(deleteSign);
if (deleteInfoArr.Length > )
{
string sql = "";
returnValue = deleteInfoArr[];
switch (deleteInfoArr[].ToLower())
{
case "complaint":
sql = "update PS_Complaint set RecordStatus='Inactive' where ComplaintID=@id";
break;
}
if (!string.IsNullOrEmpty(sql))
{
DataAccessHelper.ExecuteNonQuery(sql, new DbParameterHelper("id", DbType.Int32, deleteInfoArr[]));
}
}
}
#endregion
}