Reset Built-In Dock State Persistence

4 posts, 1 answers
  1. Matt
    Matt avatar
    33 posts
    Member since:
    Nov 2010

    Posted 27 Aug 2014 Link to this post

    Hi,

    I have a RadDockLayout control with 2 zones and 4 dock and I want to remember the positions and states of the docks. The Built-In Dock State Persistence works for me (other examples change the size of the docks when loading).

    However, I would like to implement a 'Reset Layout' button. How do you clear the built-in dock states?

    Thanks in advance,
    Matt
  2. Answer
    Slav
    Admin
    Slav avatar
    1356 posts

    Posted 29 Aug 2014 Link to this post

    Hi,

    You can clear the dock state by deleting the information from the data repository that you chose via the LayoutPersistenceRepositoryType property of RadDockLayout.

    The dock state can be in a cookie with a key that matches the value of RadDockLayout's LayoutRepositoryID property if you have set LayoutPersistenceRepositoryType=Cookies; in a file that is located in the App_Data folder of the application if you have set LayoutPersistenceRepositoryType=FileSystem; or in a data repository of your choosing if LayoutPersistenceRepositoryType=Custom.

    You can check the following article for more information about how the dock state is stored in different repository types, so that you ca find it and clear it: http://www.telerik.com/help/aspnet-ajax/dock-built-in-state-persistence.html

    Regards,
    Slav
    Telerik
     

    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

     
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Matt
    Matt avatar
    33 posts
    Member since:
    Nov 2010

    Posted 29 Aug 2014 in reply to Slav Link to this post

    Hi Slav.

    Thanks for your reply. So I made the following changes;
    .aspx
    <telerik:RadButton ID="btnRestLayout" runat="server" Text="Reset Layout" OnClick="btnRestLayout_Click" />
         <telerik:RadDockLayout ID="radDockLayout" runat="server" EnableLayoutPersistence="true" LayoutPersistenceRepositoryType="Cookies"
                LayoutRepositoryID="DockLayoutSettings">
    ...
    </telerik:RadDockLayout>

    .cs
    protected void btnRestLayout_Click(object sender, System.EventArgs e)
            {
                if (Request.Cookies[radDockLayout.LayoutRepositoryID] != null)
                {
                    HttpCookie myCookie = new HttpCookie(radDockLayout.LayoutRepositoryID)
                    {
                        Expires = DateTime.Now.AddDays(-1d)
                    };
                     
                    Response.Cookies.Add(myCookie);
     
                    HttpContext.Current.Session.Abandon();
                }
            }

    This works, however I had to abandon the session to get the full effect of clearing the cookie. Abandoning the session badly effects my web app :(

    Thanks again,
    Matt
  5. Danail Vasilev
    Admin
    Danail Vasilev avatar
    1494 posts

    Posted 03 Sep 2014 Link to this post

    Hi Matt,

    Generally the state of the RadDockLayout is saved in the SaveStateComplete event, so that in order to delete the repository cookie/file you must do that after the saving. This can be done for example by attaching to the SaveStateComplete event from a button click as follows:
    ASPX:
    <telerik:RadScriptManager runat="server" ID="RadScriptManager1" />
    <asp:Button runat="server" ID="ButtonPostback" Text="Save State"></asp:Button>
    <telerik:RadButton ID="RadButton1" runat="server" Text="Clear State" OnClick="Button1_Click" />
    <br />
    <br />
    <telerik:RadDockLayout runat="server" ID="RadDockLayout1" EnableLayoutPersistence="true" LayoutPersistenceRepositoryType="Cookies"
        LayoutRepositoryID="DockLayout">
        <telerik:RadDockZone runat="server" ID="RadDockZone1" Width="300" MinHeight="200"
            Style="float: left; margin-right: 20px;">
            <telerik:RadDock runat="server" ID="RadDock1" Title="RadDock 1" Width="300" Height="100">
            </telerik:RadDock>
        </telerik:RadDockZone>
        <telerik:RadDockZone Width="300" MinHeight="200" runat="server" ID="RadDockZone2"
            Style="float: left;">
            <telerik:RadDock runat="server" ID="RadDock2" Title="RadDock 2" Width="300" Height="100">
            </telerik:RadDock>
        </telerik:RadDockZone>
        <br class="qsf-clear-float" />
    </telerik:RadDockLayout>

    C#:
    protected void ClearState(object sender, EventArgs e)
    {
        if (Request.Cookies[RadDockLayout1.LayoutRepositoryID] != null)
        {
            HttpCookie myCookie = new HttpCookie(RadDockLayout1.LayoutRepositoryID)
            {
                Expires = DateTime.Now.AddDays(-1d)
            };
     
            Response.Cookies.Add(myCookie);
        }
        //LayoutPersistenceRepositoryType="FileSystem" :
        //System.IO.File.Delete(Server.MapPath("~/App_Data/DockLayout"));
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        Page.SaveStateComplete += ClearState;
    }

    You can also use this approach for LayoutPersistenceRepositoryType="FileSystem". The full runnable VS example on this regard can be found in the attached archive.

    Regards,
    Danail Vasilev
    Telerik
     

    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

     
Back to Top