zoukankan      html  css  js  c++  java
  • 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
    }
  • 相关阅读:
    Ubuntu 18.04.4 系统优化
    Ubuntu 18.04.4 LTS 更换国内系统源
    django 数据库迁移
    django2.0解决跨域问题
    python requests get请求传参
    python 常用排序方法
    python 电脑说话
    centos6.x配置虚拟主机名及域名hosts
    php 合并,拆分,追加,查找,删除数组教程
    PHP统计在线用户数量
  • 原文地址:https://www.cnblogs.com/huangjianwu/p/4539139.html
Copyright © 2011-2022 走看看