ClientScript.GetCallbackEventReference实现局部刷新


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

优质内容筛选与推荐>>
1、[转载]Linux用户管理全攻略(七)
2、Type of the default value for 'searches' prop must be a function 如何解决vue中报出的这种错误
3、DataSet的DataTable高效插入到数据库表
4、eclipse 引入 没有.project文件的方法
5、SharePoint branding site estimation


长按二维码向我转账

受苹果公司新规定影响,微信 iOS 版的赞赏功能被关闭,可通过二维码转账支持公众号。

    阅读
    好看
    已推荐到看一看
    你的朋友可以在“发现”-“看一看”看到你认为好看的文章。
    已取消,“好看”想法已同步删除
    已推荐到看一看 和朋友分享想法
    最多200字,当前共 发送

    已发送

    朋友将在看一看看到

    确定
    分享你的想法...
    取消

    分享想法到看一看

    确定
    最多200字,当前共

    发送中

    网络异常,请稍后重试

    微信扫一扫
    关注该公众号





    联系我们

    欢迎来到TinyMind。

    关于TinyMind的内容或商务合作、网站建议,举报不良信息等均可联系我们。

    TinyMind客服邮箱:support@tinymind.net.cn