zoukankan      html  css  js  c++  java
  • 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.

  • 相关阅读:
    线上故障排查 | 烂代码引发的血案
    源码分析系列 | 从零开始写MVC框架
    (原创干货)市场、销售-日常思考实战框架学习第三天
    (原创干货)企业管理-日常思考实战框架学习第二天
    (原创干货)人事管理-日常思考实战框架学习第一天
    带你认识物理机服务器(非原创)
    JSP高级功能-java之JSP学习第三天(非原创)
    常见指令与功能介绍-java之JSP学习第二天(非原创)
    JSP介绍与语法-java之JSP学习第一天(非原创)
    java之properties和yml两种配置文件比较(非原创)
  • 原文地址:https://www.cnblogs.com/qqhfeng/p/10284012.html
Copyright © 2011-2022 走看看