CustomJSProperties珍藏版。目的是减少客户端的代码数量,但是又能将服务器数据传输给客户端。关键是:数据是实时更新的!!!!
[这是帮助文档的说明]
CustomJSProperties Event
The CustomJSProperties event fires each time a control callback or page postback is sent to the server side. The
event enables you to declare temporary client properties using the event parameter's
CustomJSPropertiesEventArgs.Properties property, which is a collection of property names and their values. Once
declared, a property can be accessed on the client.
Note
Typically, using the JSProperties property will be more convenient and efficient than handling the
CustomJSProperties event, which is primarily declared for backward compatibility
Last month, I was creating a sample with the ASPxGridView when I needed to access the PageIndex property from the client side. The PageIndex property holds the current page index number. I needed to use the PageIndex for a client side function. Unfortunately, this property was only available on the server side. I used my keen insight to come up with the perfect suggestion to enhance the product: Just open up a bunch of server properties on the client side! Luckily, someone smarter than me (Andrew the ASPxGridView Architect) saw what a horrible idea that really was and came up with this enhancement that works better and does more...
A new method allows you to expose almost any server side property to the client side.
Using an ingenious technique which creates temporary client properties so that the client side is not weighed down with extra HTML or JavaScript if it's not needed.
【有一种方法可以向客户端提供服务器的任何属性,目的是使得客户端比较小,仅仅下载需要的代码,目的是提升速度】
The CustomJSProperties event enables you to declare temporary client properties. Once declared, these properties can be accessed from the client side. To add a new property, use the event parameter's http://documentation.devexpress.com/#AspNet/clsDevExpressWebASPxGridViewASPxGridViewClientJSPropertiesEventArgstopic property (this represents a collection of property names and their values).
For example, to expose the PageIndex property, first override the CustomJSProperties event and add your custom property to expose to the client side:
protected void ASPxGridView1_CustomJSProperties(object sender,
DevExpress.Web.ASPxGridView.ASPxGridViewClientJSPropertiesEventArgs e)
{
e.Properties["cpPageIndex"] = ASPxGridView1.PageIndex;
}
That's it, your done. Now you're free to call this property from the client side:
<input id="Button2" type="button" value="Active Page"
onclick="alert(grid.cpPageIndex)" />
To avoid rewriting the ASPxGridView’s base properties, prefix the client side property name with "cp" for custom property (e.g. cpPageIndex).
Here is a sample project that shows how it’s done: [CustomJSProperties.zip]
Thanks.
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="CustomJSProperties.aspx.cs" Inherits="CustomJSProperties" %> <%@ Register assembly="DevExpress.Web.v17.2, Version=17.2.7.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" namespace="DevExpress.Web" tagprefix="dx" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div> <asp:AccessDataSource ID="AccessDataSource1" runat="server"
DataFile="~/App_Data/nwind.mdb"
SelectCommand="SELECT [CustomerID], [CompanyName], [ContactName], [City], [Country] FROM [Customers]">
</asp:AccessDataSource> <dx:ASPxGridView ID="ASPxGridView2" runat="server" AutoGenerateColumns="False"
DataSourceID="AccessDataSource1" KeyFieldName="CustomerID"
ClientInstanceName="grid"
oncustomjsproperties="ASPxGridView2_CustomJSProperties">
<Columns>
<dx:GridViewDataTextColumn FieldName="CustomerID" ReadOnly="True"
VisibleIndex="">
</dx:GridViewDataTextColumn>
<dx:GridViewDataTextColumn FieldName="CompanyName" VisibleIndex="">
</dx:GridViewDataTextColumn>
<dx:GridViewDataTextColumn FieldName="ContactName" VisibleIndex="">
</dx:GridViewDataTextColumn>
<dx:GridViewDataTextColumn FieldName="City" VisibleIndex="">
</dx:GridViewDataTextColumn>
<dx:GridViewDataTextColumn FieldName="Country" VisibleIndex="">
</dx:GridViewDataTextColumn>
</Columns>
</dx:ASPxGridView>
<dx:ASPxButton ID="ASPxButton2" runat="server" EnableTheming="True"
Text="查询当前页码" Theme="Material">
<clientsideevents click="function(s, e) {
alert(grid.cpPageIndex);
}" />
</dx:ASPxButton>
<br /> </div>
</form>
</body>
</html>
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq; public partial class CustomJSProperties : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{ } //实时提供服务器变量
protected void ASPxGridView2_CustomJSProperties(object sender, DevExpress.Web.ASPxGridViewClientJSPropertiesEventArgs e)
{
e.Properties["cpPageIndex"] = ASPxGridView2.PageIndex + ;
}
}
CustomJSProperties珍藏版。目的是减少客户端的代码数量,但是又能将服务器数据传输给客户端。关键是:数据是实时更新的!!!!的更多相关文章
- WCF客户端调用服务器端错误:"服务器已拒绝客户端凭据"。
WCF客户端和服务器端不在同一台机器上时,客户端调用服务器端会报如下错误:"服务器已拒绝客户端凭据". 解决办法:在服务端配置文件与客户端配置文件中加入下面红色部分
- C# WebSocket 服务端示例代码 + HTML5客户端示例代码
WebSocket服务端 C#示例代码 using System; using System.Collections.Generic; using System.Linq; using System. ...
- 根据服务端生成的WSDL文件创建客户端支持代码的三种方式
第一种:使用wsimport是JDK自带的工具,来生成 生成java客户端代码常使用的命令参数说明: 参数 说明 -p 定义客户端生成类的包名称 -s 指定客户端执行类的源文件存放目录 -d 指定客户 ...
- python的select服务端的代码和客户端的代码
服务端的代码 import socket import queue import select ip_bind = ("127.0.0.1",9000) message_queue ...
- NSwag生成客户端调用代码
NetCore2.1 WebAPI 根据swagger.json自动生成客户端代码 https://www.cnblogs.com/hunanzp/p/9297361.html 前言 上一篇博客中我们 ...
- JAVA服务器与C#客户端的通信技术调研
JAVA服务器与C#客户端的通信技术调研 研究背景及目的: ARPG项目的需求:需要将现有的服务器从C++的编写平台换为java语言.在对需求进行分析的过程中,发现几点需要研究实现的问题 java与c ...
- 分析Memcached客户端如何把缓存数据分布到多个服务器上
Memcached客户端可以设多个memcached服务器,它是如何把数据分发到各个服务器上,而使各个服务器负载平衡的呢? 可以看看.net版中的客户端中的源码,就可以知道 先看代码: 1 /// ...
- Python/dotNET Redis服务连接客户端调用SET方法的同时获取Redis服务器返回的内容
在用Python或dotNET redis客户端连接redis服务器的时候,当你调用客户端的SET方法后同时还想得到其返回的字符串,那么需要处理一下. 1. Redis Python redis客户端 ...
- winform客户端利用webClient实现与Web服务端的数据传输
由于项目需要,最近研究了下WebClient的数据传输.关于WebClient介绍网上有很多详细介绍,大概就是利用WebClient可以实现对Internet资源的访问.无外乎客户端发送请求,服务端处 ...
随机推荐
- hadoop-n.x.y.tar.gz、hadoop-n.x.y.tar.gz.asc 、hadoop-n.x.y.tar.gz.md5 、hadoop-n.x.y.tar.gz.mds分别是什么?
不多说,直接上干货! 我这里,以hadoop-2.6.0为例. hadoop-n.x.y.tar.gz.mds,此mds文件是为了检验在下载和移动文件过程中文件的完整性. 通过验证文件的md5值去检验 ...
- LinkedList的自定义实现
一.背景 LinkedList双向链表: 代码: Node.java: package com.cy.collection; public class Node { Node previous; // ...
- random 产生一个随机数的方法
import random print( random.randint(1,10) ) # 产生 1 到 10 的一个整数型随机数 print( random.random() ) # 产生 0 到 ...
- 微信小程序调用微信登陆获取openid及用户信息 java做为服务端
转载的文章,很不错 https://blog.csdn.net/weilai_zhilu/article/details/77932630
- C语言强化——排序
1.完成堆排,对比堆排和qsort在排序1亿数的时间差异 #include<stdio.h> #include<time.h> #include<stdlib.h> ...
- 初始化ha环境下的hadoop的hdfs
1)启动zookeeper2)启动所有的journalnode[hadoop@datanode1 ~]$ ~/hadoop-2.7.3/sbin/hadoop-daemon.sh start jour ...
- Idea 2018版破解
刚把idea升级到最新版,发现要重新激活,网上查了有改host的方法可行,只是有点麻烦.无意中发现一个方法,如图所示 输入 http://idea.java.sx/ 即可,亲测可用.如果资金 ...
- ZBrush常用3D术语
转自:http://www.zbrushcn.com/jichu/zbrush-cy-3dsys.html Polygon(多边形) 多边形是一种形状,通过在3D空间连接几个点而创建,最简单的形式就是 ...
- Linux下安装与卸载anaconda
安装:到安装文件夹的目录下输入 bash Anaconda3-4.1.1-Linux-x86_64.sh 卸载:输入
- VMware安装CentOS7踩坑
1.VMware安装Centos7加载界面不显示,但有快照 单击“开始”,运行中输入cmd. 然后输入命令 netsh winsock reset. 重启计算机. 2.nat模式网络问题 ...