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

breaking change in 2010 Q3 - positions and indices

5 Answers 61 Views
Dock
This is a migrated thread and some comments may be shown as answers.
Danko
Top achievements
Rank 1
Danko asked on 22 Dec 2010, 03:43 PM
Hi,

We save the location of raddocks on our page with the following code:

void MainRadDockLayout_LoadDockLayout(object sender, DockLayoutEventArgs e)
{
...
e.Positions = serializer.Deserialize<Dictionary<string, string>>(positionsAndIndices[0].ToString());
e.Indices = serializer.Deserialize<Dictionary<string, int>>(positionsAndIndices[1].ToString());
...
}

Where positionsAndIndicies is a json string. This used to work until we upgraded to Q3 2010 and now we get an error:

Property or indexer 'Telerik.Web.UI.DockLayoutEventArgs.Positions' cannot be assigned to -- it is read only
Property or indexer 'Telerik.Web.UI.DockLayoutEventArgs.Indices' cannot be assigned to -- it is read only

Is there a better way to do this in the new release or should we just populate the positions and indices in a loop with e.Indices.Add(...)?

Thanks

5 Answers, 1 is accepted

Sort by
0
Accepted
Pero
Telerik team
answered on 22 Dec 2010, 05:26 PM
Hi Danko,

Please excuse us for the inconvenience!

You must loop through every value of the deserialized collections, and add it to the respective Positions/Indices dictionaries.

Best wishes,
Pero
the Telerik team
Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.
0
Shawn R.
Top achievements
Rank 1
answered on 15 Feb 2011, 05:14 PM
As I had no idea what I was doing and finally figured out how to make it work, I thought I'd post the code I used for others - VB though.

Dim positions As Dictionary(Of String, String) = serializer.Deserialize(Of Dictionary(Of String, String))(positionsAndIndices(0))
        Dim indices As Dictionary(Of String, Integer) = serializer.Deserialize(Of Dictionary(Of String, Integer))(positionsAndIndices(1))

Dim pairPositions As KeyValuePair(Of String, String)
        For Each pairPositions In positions
            e.Positions.Add(pairPositions.Key, pairPositions.Value)
        Next

        Dim pairIndices As KeyValuePair(Of String, Integer)
        For Each pairIndices In indices
            e.Indices.Add(pairIndices.Key, pairIndices.Value)
        Next

Shawn
0
Pero
Telerik team
answered on 16 Feb 2011, 09:23 AM
Hello Shawn,

Thank you for posting your code!

I converted your VB code so it is also available in C#:
Dictionary<string, string> positions = serializer.Deserialize<Dictionary<string, string>>(positionsAndIndices[0]);
Dictionary<string, int> indices = serializer.Deserialize<Dictionary<string, int>>(positionsAndIndices[1]);
 
foreach (KeyValuePair<string, string> pairPositions  in positions)
{
    e.Positions.Add(pairPositions.Key, pairPositions.Value);
}
 
foreach (KeyValuePair<string, int> pairPositions in indices)
{
    e.Indices.Add(pairPositions.Key, pairPositions.Value);
}

PS. A handy converter is available at the following link: http://converter.telerik.com/.

Greetings,
Pero
the Telerik team
Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.
0
Simon Schofield
Top achievements
Rank 1
answered on 30 Mar 2011, 01:07 AM
Hi,

Can you provide code to show how to do this?

Thanks, Simon
0
Pero
Telerik team
answered on 30 Mar 2011, 12:26 PM
Hello Simon,

You could also loop through every item of the positions and indices collection and serialize the items one by one. Here is an example that serializes and deserializes the Positions and Indices properties of the DockLayoutEventArgs object, in the LoadDockLayout event handler. You could use it as a starting point to achieve the desired scenario:

protected void RadDockLayout1_LoadDockLayout(object sender, DockLayoutEventArgs e)
{
    //Populate the event args with the state information. The RadDockLayout control
    // will automatically move the docks according that information.
    foreach (DockState state in CurrentDockStates)
    {
        e.Positions[state.UniqueName] = state.DockZoneID;
        e.Indices[state.UniqueName] = state.Index;
    }
     
    //Serialization
    StringBuilder sb = new StringBuilder();
    foreach (var item in e.Positions)
    {
        sb.Append(item.Key);
        sb.Append(",");
        sb.Append(item.Value);
        sb.Append(",");
    }
    if (sb.Length > 0)
        sb.Remove(sb.Length - 1, 1);
    var serializedPositions = sb.ToString();
 
    sb.Clear();
    foreach (var item in e.Indices)
    {
        sb.Append(item.Key);
        sb.Append(",");
        sb.Append(item.Value);
        sb.Append(",");
    }
    if (sb.Length > 0)
        sb.Remove(sb.Length - 1, 1);
    var serializedIndices = sb.ToString();
    var cookieValue = string.Concat(serializedPositions, "|", serializedIndices);
 
 
    //Deserialization
    if (cookieValue != "|")
    {
        var posAndInd = cookieValue.Split('|');
        var positions = posAndInd[0].Split(',');
        var indices = posAndInd[1].Split(',');
 
        var length = positions.Length;
        for (int i = 0; i < length; i = i + 2)
        {
            e.Positions[positions[i]] = positions[i + 1];
            e.Indices[indices[i]] = Convert.ToInt32(indices[i + 1]);
        }
    }
}

I hope this helps.

All the best,
Pero
the Telerik team
Tags
Dock
Asked by
Danko
Top achievements
Rank 1
Answers by
Pero
Telerik team
Shawn R.
Top achievements
Rank 1
Simon Schofield
Top achievements
Rank 1
Share this question
or