RadTreeView1.GetXml not saving client side node state

3 posts, 1 answers
  1. Carl
    Carl avatar
    2 posts
    Member since:
    Mar 2012

    Posted 20 Mar 2012 Link to this post

    Hi all,

    I'm using RadTreeView1.GetXml to save the state of my TreeView and repopulate it after postbacks.

    I've done a test by replaceing text in a node, and based on that I can tell that saving and repopulating the TreeView is working fine.

    The problem is that when I contract some of the nodes, then select(Click on) a node, there is a posteback, and all the nodes are revertted to thier expanded state again.

    Expanding and contracting nodes seems to be happening on the client side,  as there is no postback when this happens.
    The postback dose happen when I click on a spesific node, that is when I use GetXml to save the state, but it dose not seem to be saving the updated state on the nodes.

    Here is the code, Please let me know what I am missing here.
    <telerik:RadTreeView ID="RadTreeView1" Runat="server"
        OnNodeClick="RadTreeView1_NodeClick" EnableDragAndDrop="True" Skin="Vista"
        OnContextMenuItemClick="RadTreeView1_ContextMenuItemClick"
        OnNodeEdit="RadTreeView1_NodeEdit" OnNodeDrop="RadTreeView1_HandleDrop"
        SingleExpandPath="True" EnableViewState="true" >
        <ContextMenus>
                 <telerik:RadTreeViewContextMenu ID="RightClick" runat="server">
                    <Items>
                    <telerik:RadMenuItem Value="NewParentNode" Text="Create New Parent Folder" >
                        </telerik:RadMenuItem>
                        <telerik:RadMenuItem Value="NewNode" Text="Create New Folder" >
                        </telerik:RadMenuItem>
                        <telerik:RadMenuItem IsSeparator="true">
                        </telerik:RadMenuItem>
                        <telerik:RadMenuItem Value="NewVirtualDocument" Text="New Virtual Document" >
                        </telerik:RadMenuItem>
                        <telerik:RadMenuItem Value="UploadPDF" Text="Upload PDF" >
                        </telerik:RadMenuItem>
                        <telerik:RadMenuItem IsSeparator="true">
                        </telerik:RadMenuItem>
                        <telerik:RadMenuItem Value="DeleteNode" Text="Delete Folder" >
                        </telerik:RadMenuItem>
                    </Items>
                    <CollapseAnimation Type="none" />
                </telerik:RadTreeViewContextMenu>
          </ContextMenus>
    </telerik:RadTreeView>
    and server side
    protected void RadTreeView1_NodeClick(object sender, RadTreeNodeEventArgs NodeEvent)
    {
        clickedNode = NodeEvent.Node;
        ViewState["ClickedNode"] = clickedNode.Value.ToString();
        createDynamicTable(Convert.ToInt32(ViewState["ClickedNode"].ToString()));
     
        string savetreeViewState = RadTreeView1.GetXml();
        savetreeViewState = savetreeViewState.Replace("South Africa", "save state is working");
        Session["myTreeView"] = savetreeViewState;
     }

    Thank you for your time.
  2. Answer
    Dimitar Terziev
    Admin
    Dimitar Terziev avatar
    1266 posts

    Posted 23 Mar 2012 Link to this post

    Hi,

    In order to save the expended state of the RadTreeNodes you could use the approach from the following code library here.

    Greetings,
    Dimitar Terziev
    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.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Carl
    Carl avatar
    2 posts
    Member since:
    Mar 2012

    Posted 26 Mar 2012 Link to this post

    Thanks Dimitar, that fixed the problem.

     

    For anybody else who stumbles onto this thread with the same problem, the code library that Dimitar provided uses a cookie and JavaScript solution instead of the GetXml.


    Regards
Back to Top