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资源的访问.无外乎客户端发送请求,服务端处 ...
随机推荐
- Tomcat实战-调优方案
Tomcat的默认配置,性能并不是最优的,可以通过优化tomcat以此来提高网站的并发能力.提高Tomcat的性能可以分为两个方向. 服务器资源 服务器所能提供CPU.内存.硬盘的性能对处理能力有决定 ...
- ALGO-119_蓝桥杯_算法训练_寂寞的数
问题描述 道德经曰:一生二,二生三,三生万物. 对于任意正整数n,我们定义d(n)的值为为n加上组成n的各个数字的和.例如,d()=++=, d()=++++=. 因此,给定了任意一个n作为起点,你可 ...
- C++11--右值引用(Perfect Forwarding)
/* * 右值引用 2: Perfect Forwarding */ void foo( boVector arg ); // boVector既有移动构造又有拷贝构造 template< ty ...
- python之全局安装包管理工具pip
1.curl 'https://bootstrap.pypa.io/get-pip.py' > get-pip.py 2.sudo python get-pip.py 3.sudo easy_i ...
- uoj #49. 【UR #3】铀仓库
http://uoj.ac/problem/49 这题二分答案可以做,同时存在另一个直接二分的解法. 考虑对每个点,二分能向左右延伸的最大半径,由于权值范围较大,不能O(1)查询向一侧走指定距离后到达 ...
- bzoj3491: PA2007 Subsets
Description 有一个集合U={1,2,…,n),要从中选择k个元素作为一个子集A.若a∈A,则要有a*X不属于A,x是一个给定的数.求可选方案对M取模后的值. 1< = N< = ...
- 时间复杂度On和空间复杂度O1是什么意思?
(1).把输入规模看成x轴,所花时间/空间看成y轴 O(n)就是y=x,y随x的增长而线性增长.也就是成正比,一条斜线. O(1)就是y=1,是一个常量,不管x怎么变,y不变,一条与x轴平行的线. ( ...
- Consul实践指导-DNS接口
DNS是consul提供的主要查询接口之一.DNS接口允许应用程序在没有与consul高度集成的情况下使用服务发现. 例如:替代consul的HTTP API请求,主机能够通过名字查找直接使用DNS服 ...
- IDC:UPS(不间断电源)
ylbtech-IDC:UPS(不间断电源) UPS(Uninterruptible Power System/Uninterruptible Power Supply),即不间断电源,是将蓄电池(多 ...
- rsync数据备份
scp远程复制 scp是 secure copy的缩写, scp是linux系统下基于ssh登陆进行安全的远程文件拷贝命令. 命令格式: scp local_file remote_username@ ...