SaveDockLayout
The SaveDockLayout event occurs when the application needs to save the state of all the RadDock controls to storage options like the Session, a cookie, or a database. Utilize this event in the following scenarios:
-
The StoreLayoutInViewState property of the RadDockLayout control is False.
-
You want to save the state of RadDock controls when the user leaves the Web page and restore it when the user returns to the Web page.
-
The application dynamically creates RadDock controls at runtime.
The SaveDockLayout event handler receives two arguments:
-
The RadDockLayout control that is responsible for managing the layout of RadDockZone and RadDock controls. This argument is of type object, but can be cast to the RadDockLayout type.
-
A DockLayoutEventArgs object. This object provides access to layout information in two properties:
- Indices is a Dictionary that stores the Index property of all RadDock controls, accessed through the UniqueName property of the RadDock control.
- Positions is a Dictionary that stores the DockZoneID property of all RadDock controls, accessed through the UniqueName property of the RadDock control.
If the application has not explicitly set the UniqueName property of the RadDock controls, the Indices and Positions properties of the DockLayoutEventArgs object are indexed by the server-side ID of the RadDock controls.
Typically, a SaveDockLayout event handler uses the RadDockLayout control's GetRegisteredDocksState method, which returns a list of DockState objects that represent the state and position of the each RadDock control managed by the RadDockLayout:
protected void RadDockLayout1_SaveDockLayout(object sender, DockLayoutEventArgs e)
{
HttpCookie dockState = Page.Response.Cookies.Get("MyApplicationDockStates");
if (dockState == null)
{
dockState = new HttpCookie("MyApplicationDockStates");
Page.Response.Cookies.Add(dockState);
}
List<DockState> stateList = ((RadDockLayout)sender).GetRegisteredDocksState();
StringBuilder serializedList = new StringBuilder();
for (int i = 0; i < stateList.Count; i++)
{
serializedList.Append(stateList[i].ToString());
serializedList.Append("|");
}
dockState.Expires = DateTime.Today.AddMonths(1);
dockState.Value = serializedList.ToString();
}
The RadDockLayout control only manages the layout of RadDock and RadDockZone controls that are contained in its Controls collections.