·您现在的位置: 云翼网络 >> 文章中心 >> 网站建设 >> 网站建设开发 >> ASP.NET网站开发 >> ClientScript.GetCallbackEventReference实现局部刷新

ClientScript.GetCallbackEventReference实现局部刷新

作者:佚名      ASP.NET网站开发编辑:admin      更新时间:2022-07-23

使用ClientScript.GetCallbackEventReference实现局部刷新是.NET支持的一种前后台代码调用的方式;其实实现局部刷新这样方式有很多种,最经典也常用的莫过于jQuery封装好的异步调用方法(Ajax, get, getJSON, post),这里就不去多加比较,毕竟都会接触到。

 

下面是简单的例子:

页面前台关键代码:

 1 //删除投诉信息
 2 function f_DeleteComplaint() {
 3     var currentKey = gridManager.GetSelectRowKeyValue();
 4     if (currentKey != null) {
 5         if (confirm('<%=Strings.GetString("Sdelete")%>')) {
 6             var deleteInfo = "Complaint" + deleteSign + currentKey;
 7             <%=ClientScript.GetCallbackEventReference(this, "deleteInfo", "refresh", "")%>;
 8         }
 9     }
10     else {
11         alert('<%=Strings.GetString("S1044") %>!');
12     }
13 }
14 function refresh(val) {
15     switch(val.toLowerCase()){
16         case "complaint":
17             gridManager.Refresh(0);
18             break;
19     }
20 }

 

页面后台关键代码:

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 > 1)
        {
            string sql = "";
            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, new DbParameterHelper("id", DbType.Int32, deleteInfoArr[1]));
            }
        }
    }
    #endregion
}