This is a migrated thread and some comments may be shown as answers.

IClientStateManager

5 Answers 79 Views
Documentation and Tutorials
This is a migrated thread and some comments may be shown as answers.
Brett
Top achievements
Rank 1
Brett asked on 02 Dec 2014, 03:36 PM
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?

5 Answers, 1 is accepted

Sort by
0
Brett
Top achievements
Rank 1
answered on 02 Dec 2014, 03:37 PM
0
Accepted
Vasil
Telerik team
answered on 05 Dec 2014, 09:55 AM
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.

 
0
Brett
Top achievements
Rank 1
answered on 15 Dec 2014, 05:57 PM
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?
0
Brett
Top achievements
Rank 1
answered on 15 Dec 2014, 06:26 PM
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?

0
Marin
Telerik team
answered on 18 Dec 2014, 03:43 PM
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.

 
Tags
Documentation and Tutorials
Asked by
Brett
Top achievements
Rank 1
Answers by
Brett
Top achievements
Rank 1
Vasil
Telerik team
Marin
Telerik team
Share this question
or