IClientStateManager

6 posts, 1 answers
  1. Brett
    Brett avatar
    42 posts
    Member since:
    Aug 2014

    Posted 02 Dec 2014 Link to this post

    The documentation states the argument of LoadClientState is a string, this doesn't seem to be correct for RadGrid, it is a Dictionary<string,object>, and there is no overload that takes a string. 

    is there another IClientStateManager for collections?
  2. Brett
    Brett avatar
    42 posts
    Member since:
    Aug 2014
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Answer
    Vasil
    Admin
    Vasil avatar
    1547 posts

    Posted 05 Dec 2014 Link to this post

    Hello Brett,

    The method differs for different controls.
    The API reference is auto-generated from the assembly and it is correct.

    Indeed the grid's method expects dictionary. In the base class it is called during the LoadPostData method:

    protected virtual bool LoadPostData(string postDataKey, NameValueCollection postCollection)
    {
        string clientState = postCollection[ClientStateFieldID];
        if (!string.IsNullOrEmpty(clientState))
        {
            JavaScriptSerializer serializer = new JavaScriptSerializer();
            var deserializedState = serializer.DeserializeObject(clientState) as Dictionary<string, object>;
            if (deserializedState != null)
                return LoadClientState(deserializedState);
        }
        return false;
    }

    You could use the same approach with the JavaScriptSerializer class to build dictionary from JSON string.

    Regards,
    Vasil
    Telerik
     

    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

     
  5. Brett
    Brett avatar
    42 posts
    Member since:
    Aug 2014

    Posted 15 Dec 2014 in reply to Vasil Link to this post

    hmm...the method in question is a method on an interface (IClientStateManager). It cannot differ in it's digital sigature. So are you saying that controls don't implement that interface? But may very well contain a method called LoadPostData?
  6. Brett
    Brett avatar
    42 posts
    Member since:
    Aug 2014

    Posted 15 Dec 2014 in reply to Brett Link to this post

    actually.. after reviewing RadGrid in Object Browser, I'm not entirely sure how I got the impression it was implementing IClientStateManager - or a variant - in the first place.

    In your sample code, would ClientStateFieldID be a part of the postDataKey?

  7. Marin
    Admin
    Marin avatar
    1045 posts

    Posted 18 Dec 2014 Link to this post

    Hi,

    IClientStateManager is a helper interface from the Telerik library intended for use in the client state persistence feature of the controls. However not all controls implement it. Some controls, such as RadGrid have their own custom implementation of the client state persistence feature.
    A base class for most of the telerik controls that support databinding and can visualize data is the RadCompositeDataBoundControl implementing the following standard ASP.NET classes and interfaces:
    public abstract partial class RadCompositeDataBoundControl : CompositeDataBoundControl, IScriptControl, IPostBackDataHandler

    It also adds a variety of internal properties one of which is the ClientStateFieldID property:
    [ClientControlProperty] //helper attribute indicating the property value will be serialized on the client
    [Browsable(false)]
    public string ClientStateFieldID
    {
        get
        {
            return ClientID + "_ClientState";
        }
    }

    The property is used when the control renders a hidden input to hold all the client-side setting that will be serialized back to the server:
    <input id="RadGrid1_ClientState" name="RadGrid1_ClientState" type="hidden" autocomplete="off">

    The LoadPostData method as defined in the IPostBackDataHandler interface takes as first argument the key identifier for the control - which in the example above will be simply the ID of the control: RadGrid1. The second parameter is a NameValueCollection of all the data posted back to the server, among which we also have the value of the hidden input holding the client state. That's why in the LoadPostData method we use the ClientStateFieldID property to get this value and deserialize it to grid settings.
    protected virtual bool LoadPostData(string postDataKey, NameValueCollection postCollection)
            {
                string clientState = postCollection[ClientStateFieldID];

    I hope this helps.

    Regards,
    Marin
    Telerik
     

    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

     
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017