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.
in mySaveDockLayout i try to save all positions to a cookie
and on the RadDockLayout control i call the following OnLoadDockLayout="LoadDockLayout" to load my dashboard from a cookie
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?
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?