Save Dock state

7 posts, 1 answers
  1. JC
    JC avatar
    30 posts
    Member since:
    Feb 2013

    Posted 08 Mar 2013 Link to this post

    Hello,

    I am quiet confused with saving the dock state in cookie. I just need the C# code to save the dock state in the cookie and I want it to be persisted for a particular time duration.

    Please help with code,
    JC.
  2. Answer
    Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 08 Mar 2013 Link to this post

    Hello JC,

    You can use the SaveDockLayout event to achieve your requirement. The SaveDockLayout event occurs when it is appropriate for the application to save the state of all its RadDock controls to a storage medium such as the Session, a cookie, or a database. This event should be used to store the state of RadDock controls in any of the following situations:
    • 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.

    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. Please have a look into the following code.

    C#:

    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();
    }
                     
    Thanks,
    Shinu.

                                                  

  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Slav
    Admin
    Slav avatar
    1356 posts

    Posted 12 Mar 2013 Link to this post

    Hi,

    You can also try the new Built-In Dock State Persistence. It allows you to automatically store the dock state in a cookie by setting the property EnableStoreLayout of RadDockLayout to true and the property LayoutStorageType to Cookies.

    All the best,
    Slav
    the Telerik team
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
  5. Nagasree
    Nagasree avatar
    7 posts
    Member since:
    Apr 2013

    Posted 26 Apr 2013 Link to this post

    Hi Slav,

    I tried Built-In Dock State Persistence by setting the property EnableStoreLayoutPersistence of RadDockLayout to true and the property LayoutPersisitenceRepositoryType to Custom to store the dock state in a database by creating a class that implements the interface IStateStorageProvider and setting an instance of this class to the property StorageProvider of RadDockLayout.

    The state is being saved the very first time I open the page. I change the state of the docks by moving them around and minimizing and closing some, closing the page and then opening again is not storing the changed state.

    Is there any event that I need to raise to save the dock state? Am I missing something here...

    Please let me know.

    Thanks,
    NK


  6. Slav
    Admin
    Slav avatar
    1356 posts

    Posted 30 Apr 2013 Link to this post

    Hi Nagasree,

    Please ensure that the custom storage provider is set on Page_Init as shown in the online demo you linked. Also, I would suggest checking if there is a problem with writing and reading the state from your database. Examine if there is any data in the row of the database table, in which the state is stored.

    If the problem persists, you can run the demo locally (it is located in [RadControls for ASP.NET AJAX installation path]\Live Demos\Dock\Examples\BuiltInDockStatePersistence) and use it as a reference for configuring the built-in dock state persistence on your end.

    Regards,
    Slav
    the Telerik team
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
  7. Nagasree
    Nagasree avatar
    7 posts
    Member since:
    Apr 2013

    Posted 30 Apr 2013 Link to this post

    Hi Slav,

    Thank you very much for the response. So, after changing the state of the docks by moving them around, minimizing or closing them, do I need a button like "Save State" to save the state.

    In the example located in [RadControls for ASP.NET AJAX installation path]\Live Demos\Dock\Examples\BuiltInDockStatePersistence) also, the state is being saved only after clicking the button “Save State”.

    Is there a way this can be achieved without using a button? Please let me know.

    Thanks for all your help,

    NK
  8. Dobromir
    Admin
    Dobromir avatar
    1633 posts

    Posted 01 May 2013 Link to this post

    Hi NK,

    The button in the mentioned live demo is used to trigger a postback - you can achieve the required functionality without external button by setting RadDock's AutoPostBack and CommandsAutoPostBack to True to configure the control to trigger a postback itself.

    Greetings,
    Dobromir
    the Telerik team
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017