博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
使用jquery+一般处理程序异步载入信息
阅读量:6655 次
发布时间:2019-06-25

本文共 11266 字,大约阅读时间需要 37 分钟。

需求:有时候。web界面对性能要求比較高。我们就不考虑使用asp.net控件。而是使用html标签+jquery+一般处理程序来进行异步处理。

aspx代码:

<%# Container.ItemIndex +1 %> <%#Eval("name") %> <%#Eval("accountnumber") %> <%#Eval("hx_fmetercode") %>
                       
                           
                               
                                   
                                       

客户信息

                                       
                                           
客户:
                                           
                                               
                                               
                                           
                                           
编号:
                                           
                                               
                                           
                                           
电话:
                                           
                                               
                                           
                                           
手机:
                                           
                                               
                                           
                                       
                                       
                                   
                                   

                                   
                                       

水表信息

                                       
                                           
水表编码:
                                           
                                               
                                           
                                           
电子表号:
                                           
                                               
                                           
                                           
水表状态:
                                           
                                               
                                           
                                       
                                       
                                           
地址:                                           
                                           
                                               
                                           
                                       
                                       
                                   
                                   

                                   
                                       

用水信息

                                       
                                           
用水性质:
                                           
                                               
                                           
                                           
水费单位价格:
                                           
                                               
                                           
                                           
污水费单位价格:
                                           
                                               
                                           
                                       
                                       
                                           
用水人口:
                                           
                                               
                                           
                                           
是否阶梯水价:
                                           
                                               
                                           
                                           
结算前账户剩余金额:
                                           
                                               
                                           
                                       
                                       
                                   
                               
                           
                       
                   
css代码我就省略了,直接列js代码:
var getAccountInfo = function (data) {            $("#lblClientName").html(data.ClientName);            $("#lblClientNo").html(data.ClientNo);            $("#lblCell").html(data["Cell"]);            $("#lblTel").html(data["Tel"]);            $("#lblMeterCode").html(data["MeterCode"]);            $("#lblElectronicMeteNo").html(data["ElectronicMeteNo"]);            $("#lblMeterStatus").html(data["MeterStatus"]);            $("#lblMeterAddress").html(data["MeterAddress"]);            $("#lblWaterNature").html(data["WaterNature"]);            $("#lblWaterPrice").html(data["WaterPrice"]);            $("#lblSewagePrice").html(data["SewagePrice"]);            $("#lblWaterPopulation").html(data["WaterPopulation"]);            var error = data["error"];            if (error != null && error != undefined && error != "") {                error = errorMsg + error;                $("#spnError").html(error);                $("#divError").attr("visibility", "visible");            }            else {                $("#spnError").html("");                $("#divError").attr("visibility", "hidden");            };        }        //依据选中的水表来客户具体信息        function getInfoBySelect(meterId) {            $.getJSON("Handlers/PrepaymentBusinessHandler.ashx", { "meterId": meterId }, getAccountInfo);        }   $(document).ready(function () {                //$("#tbList tr:odd").addClass("alt"); 偶数行样式                //$("#tbList tr:even").css("background-color", "white"); //奇数行样式                $("#tbList tr").hover(function () { $(this).addClass('overCss'); }, function () { $(this).removeClass('overCss'); }).click(                    function (e) {                        if ($(e.srcElement || e.target).attr("type") != "radio") {                            $(this).find(":radio").click(); //$(this).find(":radio").attr("checked", true);有问题                        }                    });                $("#tbList input[type='radio']").click(function () {                    $(this).parent().parent().addClass('clickCss')                    .siblings().removeClass('clickCss')                    .end();                    getInfoBySelect($(this).val());                });            });
一般处理程序:
///     /// PrepaymentBusinessHandler 的摘要说明    ///     public class PrepaymentBusinessHandler : IHttpHandler    {        IOrganizationService _serviceProxy = PrepaymentBusinessHandle._serviceProxy;        int _maxReturnCount = 10;        string error = string.Empty;        public void ProcessRequest(HttpContext context)        {            context.Response.ContentType = "text/plain";            string meterId = context.Request["meterId"];            JavaScriptSerializer jsonSerializer = new JavaScriptSerializer();            string outputString =GetModel(meterId)==null?string.Empty: jsonSerializer.Serialize(GetModel(meterId));            if(!string.IsNullOrEmpty(error))            {                outputString =string.IsNullOrEmpty(outputString)?"{\"error\":\""+ error+"\"}":outputString.Trim('}')+",\"error\":\""+ error+"\"}";            }            context.Response.Write(outputString);        }        ///         /// 依据选择的记录获取客户具体信息        /// 水表ID        ///         /// 
EntityCollection GetAccountInfoBySelectRecord(string meterId) { EntityCollection etResults = null; if (string.IsNullOrEmpty(meterId)) { return etResults; } string fetchXml = @"
"; try { etResults = this._serviceProxy.RetrieveMultiple(new FetchExpression(fetchXml)); } catch (Exception ex) { error = ex.Message; } return etResults; } /// /// 依据水表ID获取账户具体信息 /// /// 水表ID ///
public AccountInfoEntity GetModel(string meterId) { AccountInfoEntity entity = new AccountInfoEntity(); EntityCollection entitys = GetAccountInfoBySelectRecord(meterId); if (entitys != null && entitys.Entities.Count > 0) { entity.ClientName = entitys.Entities[0].Contains("t_account.name") && entitys.Entities[0]["t_account.name"] != null ? ((AliasedValue)entitys.Entities[0].Attributes["t_account.name"]).Value.ToString() : string.Empty; entity.ClientNo = entitys.Entities[0].Contains("t_account.accountnumber") && entitys.Entities[0]["t_account.accountnumber"] != null ?

((AliasedValue)entitys.Entities[0].Attributes["t_account.accountnumber"]).Value.ToString() : string.Empty; entity.Cell = entitys.Entities[0].Contains("t_account.telephone1") && entitys.Entities[0]["t_account.telephone1"] != null ? ((AliasedValue)entitys.Entities[0].Attributes["t_account.telephone1"]).Value.ToString() : string.Empty; entity.Tel = entitys.Entities[0].Contains("t_account.telephone2") && entitys.Entities[0]["t_account.telephone2"] != null ?

((AliasedValue)entitys.Entities[0].Attributes["t_account.telephone2"]).Value.ToString() : string.Empty; entity.MeterCode = entitys.Entities[0].Contains("t_meter.hx_fmetercode") && entitys.Entities[0]["t_meter.hx_fmetercode"] != null ? ((AliasedValue)entitys.Entities[0].Attributes["t_meter.hx_fmetercode"]).Value.ToString() : string.Empty; entity.ElectronicMeteNo = entitys.Entities[0].Contains("t_meter.hx_feleno") && entitys.Entities[0]["t_meter.hx_feleno"] != null ? ((AliasedValue)entitys.Entities[0].Attributes["t_meter.hx_feleno"]).Value.ToString() : string.Empty; string state = entitys.Entities[0].Contains("t_meter.hx_fstate") && entitys.Entities[0]["t_meter.hx_fstate"] != null ?

((OptionSetValue)((AliasedValue)entitys.Entities[0]["t_meter.hx_fstate"]).Value).Value.ToString() : string.Empty; if (state == "0") { state = "新装"; }; if (state == "1") { state = "已开户"; }; if (state == "2") { state = "销户"; }; if (state == "3") { state = "停水"; }; if (state == "4") { state = "被更换"; }; if (state == "5") { state = "未开户"; }; if (state == "6") { state = "撤户停查"; }; entity.MeterStatus = state; entity.MeterAddress = entitys.Entities[0].Contains("t_meter.hx_faddres") && entitys.Entities[0]["t_meter.hx_faddres"] != null ?

((AliasedValue)entitys.Entities[0].Attributes["t_meter.hx_faddress"]).Value.ToString() : string.Empty; entity.WaterNature = entitys.Entities[0].Contains("t_fwaterproperty.hx_faliasname") && entitys.Entities[0]["t_fwaterproperty.hx_faliasname"] != null ?

((AliasedValue)entitys.Entities[0].Attributes["t_fwaterproperty.hx_faliasname"]).Value.ToString() : string.Empty; entity.WaterPrice = entitys.Entities[0].Contains("t_fwaterproperty.hx_fwaterbasicprice") && entitys.Entities[0]["t_fwaterproperty.hx_fwaterbasicprice"] != null ?

((AliasedValue)entitys.Entities[0].Attributes["t_fwaterproperty.hx_fwaterbasicprice"]).Value.ToString() : string.Empty; entity.SewagePrice = entitys.Entities[0].Contains("t_fwaterproperty.hx_fcollchargesbasicprice4") && entitys.Entities[0]["t_fwaterproperty.hx_fcollchargesbasicprice4"] != null ? ((AliasedValue)entitys.Entities[0].Attributes["t_fwaterproperty.hx_fcollchargesbasicprice4"]).Value.ToString() : string.Empty; entity.WaterPopulation = entitys.Entities[0].Contains("t_account.hx_ffamilysize") && entitys.Entities[0]["t_account.hx_ffamilysize"] != null ? ((AliasedValue)entitys.Entities[0].Attributes["t_account.hx_ffamilysize"]).Value.ToString() : string.Empty; } return entity; } public bool IsReusable { get { return false; } } } public class AccountInfoEntity { /// <summary> /// 客户名称 /// </summary> public string ClientName { get; set; } /// <summary> /// 编号 /// </summary> public string ClientNo { get; set; } /// <summary> /// 电话 /// </summary> public string Cell { get; set; } /// <summary> /// 手机 /// </summary> public string Tel { get; set; } /// <summary> /// 水表编码 /// </summary> public string MeterCode { get; set; } /// <summary> /// 电子表号 /// </summary> public string ElectronicMeteNo { get; set; } /// <summary> /// 水表状态 /// </summary> public string MeterStatus { get; set; } /// <summary> /// 水表地址 /// </summary> public string MeterAddress { get; set; } /// <summary> /// 用水性质 /// </summary> public string WaterNature { get; set; } /// <summary> /// 水费单位价格 /// </summary> public string WaterPrice { get; set; } /// <summary> /// 污水费单位价格 /// </summary> public string SewagePrice { get; set; } /// <summary> /// 用水人口 /// </summary> public string WaterPopulation { get; set; } }

思路:使用jquery发送请求,并传递參数给一般处理程序。一般处理程序从数据库中获取数据后先序列化然后再传回web界面,再使用jquery反序列化获取信息。

你可能感兴趣的文章
小白制作星空字
查看>>
004.使用MSCK命令修复Hive表分区
查看>>
ThreadLocal及Java引用类型
查看>>
iOS 设置一行颜色不同的NSString 、剪切图片、设置TableView的自定义header
查看>>
spring transaction不生效的一些原因
查看>>
我的友情链接
查看>>
详解Nginx+php-5.4+Mysql-5.5+Memcached+redis的架构部署
查看>>
Warning MVC1000
查看>>
cruisecontrol编译识别
查看>>
PHP问题 —— Notice: Undefined index:
查看>>
解决对话框字体模糊
查看>>
文件输出流
查看>>
maven跳过单元测试-maven.test.skip和skipTests的区别
查看>>
「转」 理解“统一编址与独立编址、I/O端口与I/O内存”
查看>>
jquery的异步获取返回值为中文时乱码解决方法
查看>>
Oracle in 引号连接的子查询用法
查看>>
安卓 调试笔记 不断更新
查看>>
PyPy 与 Python 的一个小 timeit (一)
查看>>
adb启动失败 , 查错: adb server version (32) doesn't match this client (39)
查看>>
项目管理-项目章程
查看>>