[这是帮助文档的说明]

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.

Mehul Harry (DevExpress)Web Program Manager
Twitter: @Mehulharry
<%@ 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珍藏版。目的是减少客户端的代码数量,但是又能将服务器数据传输给客户端。关键是:数据是实时更新的!!!!的更多相关文章

  1. WCF客户端调用服务器端错误:"服务器已拒绝客户端凭据"。

    WCF客户端和服务器端不在同一台机器上时,客户端调用服务器端会报如下错误:"服务器已拒绝客户端凭据". 解决办法:在服务端配置文件与客户端配置文件中加入下面红色部分

  2. C# WebSocket 服务端示例代码 + HTML5客户端示例代码

    WebSocket服务端 C#示例代码 using System; using System.Collections.Generic; using System.Linq; using System. ...

  3. 根据服务端生成的WSDL文件创建客户端支持代码的三种方式

    第一种:使用wsimport是JDK自带的工具,来生成 生成java客户端代码常使用的命令参数说明: 参数 说明 -p 定义客户端生成类的包名称 -s 指定客户端执行类的源文件存放目录 -d 指定客户 ...

  4. python的select服务端的代码和客户端的代码

    服务端的代码 import socket import queue import select ip_bind = ("127.0.0.1",9000) message_queue ...

  5. NSwag生成客户端调用代码

    NetCore2.1 WebAPI 根据swagger.json自动生成客户端代码 https://www.cnblogs.com/hunanzp/p/9297361.html 前言 上一篇博客中我们 ...

  6. JAVA服务器与C#客户端的通信技术调研

    JAVA服务器与C#客户端的通信技术调研 研究背景及目的: ARPG项目的需求:需要将现有的服务器从C++的编写平台换为java语言.在对需求进行分析的过程中,发现几点需要研究实现的问题 java与c ...

  7. 分析Memcached客户端如何把缓存数据分布到多个服务器上

    Memcached客户端可以设多个memcached服务器,它是如何把数据分发到各个服务器上,而使各个服务器负载平衡的呢? 可以看看.net版中的客户端中的源码,就可以知道 先看代码:   1 /// ...

  8. Python/dotNET Redis服务连接客户端调用SET方法的同时获取Redis服务器返回的内容

    在用Python或dotNET redis客户端连接redis服务器的时候,当你调用客户端的SET方法后同时还想得到其返回的字符串,那么需要处理一下. 1. Redis Python redis客户端 ...

  9. winform客户端利用webClient实现与Web服务端的数据传输

    由于项目需要,最近研究了下WebClient的数据传输.关于WebClient介绍网上有很多详细介绍,大概就是利用WebClient可以实现对Internet资源的访问.无外乎客户端发送请求,服务端处 ...

随机推荐

  1. PowerPoint’s Menu is Too Big

    转自: http://jdav.is/2016/08/31/powerpoints-menu-is-too-big/ It seems that when Microsoft deployed the ...

  2. problem:vue之数据变更没有触发视图更新问题

    前言: 数据变更之后,vue如何渲染dom? 实际场景: 更新数据之后,再设置滚动条的位置为什么设置无效? 为什么将隐藏的元素设置为显示状态之后,读取元素状态读取不到? 改变了对象/数组中的值,页面没 ...

  3. PAT 乙级 1005 继续(3n+1)猜想 (25) C++版

    1005. 继续(3n+1)猜想 (25) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 8000 B 判题程序 Standard 作者 CHEN, Yue 卡拉兹(Callatz ...

  4. 自动化 数据分离 --A文件里面的类 中的函数 调用 B文件里面类 的函数 的方法

    记录: bb 要实例化 self.dr=dr,那么 iber_test类的 self.dr 才能带过去

  5. 如何修改CSV文件的分隔符

    Excel转成CSV文件,在Windows下默认的列表分隔符是逗号(,).在某些情况下,我们可能需要更改列表分隔符,如某个单元格内容包含逗号,而这可能导致使用它的程序出错,这样就需要更改列表分隔符:再 ...

  6. chrome不好用

    (也是写于很久很久以前) 因为工作的某些原因,我本来想换Google chrome作为默认浏览器,真正用它的时候,才发现它一点都不好用,首先它很多网站不支持或显示不完整,比如新浪邮箱,打开新浪邮箱只显 ...

  7. oracle em管理平台

      检查em有没有打开     https://172.30.2.120:1158/em/console/logon/logon   输入你配置的账号密码       界面如下图所示  

  8. HDOJ 2004 成绩转换

    #include<cstdio> #include<iostream> using namespace std; int main() { int score; while ( ...

  9. library之目录

    组件之fragment: Android viewpager结合fragment的相关优化: 组件之webview: WebView的使用及实战(cookie同步和cookie清除); Android ...

  10. xml布局解析报错的可能原因

    xml布局解析报如下的错11-15 16:55:21.425 17633-17633/com.hongfans.mobileconnect I/LogUtils_info: [CrashHandler ...