Save Layout OnPositionChanged

2 posts, 1 answers
  1. Atimo Personeelstechniek
    Atimo Personeelstechniek avatar
    1 posts
    Member since:
    Dec 2009

    Posted 03 Aug 2010 Link to this post


    I'm trying to create some autosave functionality to fire after the position of my docks change.

    i have created the folowing event for the on change to fire.

    internal void DockPositionChanged(object sender, DockPositionChangedEventArgs e)
                RadDock dockSender = (RadDock)sender;
                int cntDocks = 0;
                int Ix = 0;
                dockstates = DocLayoutZone.GetRegisteredDocksState();
                cntDocks = dockstates.Count;
                Dictionary<string, string> myPositions = new Dictionary<string, string>();
                Dictionary<string, int> myIndices = new Dictionary<string, int>();
                while (Ix < cntDocks)
                    if (dockSender.DockZoneID == dockstates[Ix].UniqueName)
                        myPositions.Add(dockstates[Ix].UniqueName, e.DockZoneID);
                        myIndices.Add(dockstates[Ix].UniqueName, e.Index);
                        myPositions.Add(dockstates[Ix].UniqueName,  dockstates[Ix].DockZoneID);
                        myIndices.Add(dockstates[Ix].UniqueName, dockstates[Ix].Index);
                Telerik.Web.UI.DockLayoutEventArgs myEvent = new DockLayoutEventArgs(myPositions, myIndices);
                mySaveDockLayout(sender, myEvent, dockstates);
    in mySaveDockLayout i try to save all positions to a cookie
    protected void mySaveDockLayout(object sender, Telerik.Web.UI.DockLayoutEventArgs e, List<DockState> dockStates)
                JavaScriptSerializer serializer = new JavaScriptSerializer();
                string serializedPositions = serializer.Serialize(e.Positions);
                string serializedIndices = serializer.Serialize(e.Indices);
                string serializedDockStates = serializer.Serialize(dockStates);
                HttpCookie positionsCookie = new HttpCookie("DockLayout",
                    serializer.Serialize(new string[] { serializedPositions, serializedIndices, serializedDockStates }));
                positionsCookie.Expires = DateTime.Now.AddYears(1);

    and on the RadDockLayout control i call the following OnLoadDockLayout="LoadDockLayout" to load my dashboard from a cookie
    internal void LoadLayout(HttpContext httpContext, DockLayoutEventArgs e, RadDockLayout dockLayout)
                HttpCookie positionsCookie = httpContext.Request.Cookies["DockLayout"];
                if (!Object.Equals(positionsCookie, null))
                    string serializedPositionsAndIndices = positionsCookie.Value;
                    if (!string.IsNullOrEmpty(serializedPositionsAndIndices))
                        JavaScriptSerializer serializer = new JavaScriptSerializer();
                        string[] positionsAndIndices = serializer.Deserialize<string[]>(serializedPositionsAndIndices);
                        e.Positions = serializer.Deserialize<Dictionary<string, string>>(positionsAndIndices[0]);
                        e.Indices = serializer.Deserialize<Dictionary<string, int>>(positionsAndIndices[1]);
                        if (positionsAndIndices.Length > 2)
                            List<DockState> dockStates = serializer.Deserialize<List<DockState>>(positionsAndIndices[2]);
                            foreach (DockState state in dockStates)
                                RadDock dock = (RadDock)dockLayout.FindControl(state.UniqueName);
                                if (dock != null)
                                    dock.Closed = state.Closed;
                                    dock.Collapsed = state.Collapsed;
                                    dock.Pinned = state.Pinned;

    but after i restart my project my docks are set to different dockzones and not on the one i placed them before.

    Could you please shed some light on this situation?
  2. Answer
    Pero avatar
    1156 posts

    Posted 04 Aug 2010 Link to this post

    Hello Atimo,

    We have a similar sample project that saves the dockstate in cookies on a button click. I have attached it to the thread. You could modify it to suit your specific scenario. I am not sure whether it will be a problem, but the server code is in VB. The following code converter can be used to convert the code to C#:

    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  3. DevCraft R3 2016 release webinar banner
Back to Top