首页 > 学院 > 开发设计 > 正文

ClientScript.GetCallbackEventReference实现局部刷新

2019-11-14 15:59:49
字体:
来源:转载
供稿:网友

使用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}

 


发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表