breaking change in 2010 Q3 - positions and indices

6 posts, 1 answers
  1. Danko
    Danko avatar
    4 posts
    Member since:
    May 2008

    Posted 22 Dec 2010 Link to this post

    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
  2. Answer
    Pero
    Admin
    Pero avatar
    1156 posts

    Posted 22 Dec 2010 Link to this post

    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.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Shawn R.
    Shawn R. avatar
    4 posts
    Member since:
    Nov 2008

    Posted 15 Feb 2011 Link to this post

    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
  5. Pero
    Admin
    Pero avatar
    1156 posts

    Posted 16 Feb 2011 Link to this post

    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.
  6. Simon Schofield
    Simon Schofield avatar
    1 posts
    Member since:
    May 2010

    Posted 29 Mar 2011 Link to this post

    Hi,

    Can you provide code to show how to do this?

    Thanks, Simon
  7. Pero
    Admin
    Pero avatar
    1156 posts

    Posted 30 Mar 2011 Link to this post

    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
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017