New to Telerik UI for ASP.NET AJAX? Download free 30-day trial


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:

  1. 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.

  2. 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");
    List<DockState> stateList = ((RadDockLayout)sender).GetRegisteredDocksState();
    StringBuilder serializedList = new StringBuilder();
    for (int i = 0; i < stateList.Count; i++)
    dockState.Expires = DateTime.Today.AddMonths(1);
    dockState.Value = serializedList.ToString();
Protected Sub RadDockLayout1_SaveDockLayout( _
                 ByVal sender As Object, _
                 ByVal e As DockLayoutEventArgs) _
                 Handles RadDockLayout1.SaveDockLayout
    Dim dockState As HttpCookie = Page.Response.Cookies.[Get]("MyApplicationDockStates")
    If dockState Is Nothing Then
        dockState = New HttpCookie("MyApplicationDockStates")
    End If
    Dim stateList As List(Of DockState) = (DirectCast(sender, RadDockLayout)).GetRegisteredDocksState()
    Dim serializedList As New StringBuilder()
    Dim i As Integer = 0
    While i < stateList.Count
        System.Math.Max(System.Threading.Interlocked.Increment(i), i - 1)
    End While
    dockState.Expires = DateTime.Today.AddMonths(1)
    dockState.Value = serializedList.ToString()
End Sub

The RadDockLayout control only manages the layout of RadDock and RadDockZone controls that are contained in its Controls collections.

See Also

In this article