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

Save Layout OnPositionChanged

1 Answer 65 Views
Dock
This is a migrated thread and some comments may be shown as answers.
Atimo Personeelstechniek
Top achievements
Rank 1
Atimo Personeelstechniek asked on 03 Aug 2010, 09:45 AM
Hi,

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);
                }
                else
                {
                    myPositions.Add(dockstates[Ix].UniqueName,  dockstates[Ix].DockZoneID);
                    myIndices.Add(dockstates[Ix].UniqueName, dockstates[Ix].Index);
                }
                Ix++;
            }          
             
            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);
            HttpContext.Current.Response.Cookies.Add(positionsCookie);                     
        }

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?

1 Answer, 1 is accepted

Sort by
0
Accepted
Pero
Telerik team
answered on 04 Aug 2010, 03:48 PM
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#: http://converter.telerik.com/.

Greetings,
Pero
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
Tags
Dock
Asked by
Atimo Personeelstechniek
Top achievements
Rank 1
Answers by
Pero
Telerik team
Share this question
or