RadTreeView save expanded state

35 posts, 0 answers
  1. Ryan
    Ryan avatar
    6 posts
    Member since:
    Aug 2008

    Posted 11 Aug 2008 Link to this post

    Is there any easy way to save the expanded nodes so that when directed away from  the page and coming back, you still have the same nodes expanded as when you left?  I am using a sql database to populate the treeview and all methods i have tried i have been having problems with serialization because it is using SQL im assuming thats why.  I tried to store the expansion states in a session variable and had no luck.  So is there any really easy way to accomplish this?  Any help would be greatly appreciated.  Thanks!
  2. Veselin Vasilev
    Admin
    Veselin Vasilev avatar
    2992 posts

    Posted 12 Aug 2008 Link to this post

    Hi Ryan,

    How exactly did you use the Session variable?
    You can store the state of the treeview in the session like this:

    Session["myTreeView"] = RadTreeView1.GetXml(); 

    and later restore the treeview state from that session variable:

    string treeViewState = (string)Session["treeViewState"];  
    RadTreeView1.LoadXmlString(treeViewState); 

    I hope this will get you started.

    Sincerely yours,
    Veskoni
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Ryan
    Ryan avatar
    6 posts
    Member since:
    Aug 2008

    Posted 12 Aug 2008 Link to this post

    That works wonderfully but for right now i have the save to session code in a button since i can not figure out where to place it to have it save before the user clicks a link and navigates away from the page.  Any ideas?  Like is there an onexpand event that i can have a function handle it and just dump Session("treeViewState") = RadTreeView1.GetXml() there?
  5. Ryan
    Ryan avatar
    6 posts
    Member since:
    Aug 2008

    Posted 13 Aug 2008 Link to this post

    Basically, what technique can i use so that any time a node is expanded or collapsed, i can save the treeview to session?  Since it is client side right now for me, then what can i put into the jacascript in the HTML to catch the expansion or collapsing of a node and have the code behind see the event and trigger the save to session (Session("treeViewState") = RadTreeView1.GetXml())
  6. Veselin Vasilev
    Admin
    Veselin Vasilev avatar
    2992 posts

    Posted 15 Aug 2008 Link to this post

    Hi Ryan,

    I guess you need to use a navigation control like LinkButton that will perform a postback on click and navigate after that:

    asp:LinkButton ID="LinkButton1" runat="server" OnClick="LinkButton1_Click">Click Here to navigate</asp:LinkButton> 
     
        protected void LinkButton1_Click(object sender, EventArgs e)  
        {  
            //save the session. Alternatively you can save the XML string in a temporary table in the DB  
            Session["myTreeView"] = RadTreeView1.GetXml();   
     
            //navigate  
            Response.Redirect("...");  
        } 

    I hope this helps.

    Greetings,
    Veskoni
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
  7. Ryan
    Ryan avatar
    6 posts
    Member since:
    Aug 2008

    Posted 20 Aug 2008 Link to this post

    I am kind of confused at how to implement that concept.  Here is what i tried in 1.1 and it worked.

    <radT:RadTreeView id="RadTreeView1"  BeforeClientClick="BeforeClickHandler" runat="server" NodeCssClassSelect=" "
                                NodeCssClassOver=" " NodeCssClassEdit=" " NodeCssClassDisable=" " NodeCssClass=" " Skin="TSA"></radT:RadTreeView>
                            <telerik:RadScriptManager ID="RadScriptManager1" runat="server">
                            </telerik:RadScriptManager>   
                            <telerik:RadAjaxManager ID="RadAjaxManager1" OnAjaxRequest="RadAjaxManager1_AjaxRequest" runat="server">
                            </telerik:RadAjaxManager>
                               
                                <telerik:AjaxSetting_AjaxControlID="RADAJAXMANAGER1"></TELERIK:AJAXSETTING>
                               
                                <script language="JavaScript" type="text/javascript">
                                function BeforeClickHandler()
                                {
                                <!--
                                    RadAjaxManager1.AjaxRequest();
                                    return false;
                                -->
                                }
                                </script>

    But now in 2.0 it hangs with this error upon clicking a node to be redirected Microsoft JScript runtime error: Object doesn't support this property or method
    and it is referring to the RadAjaxManager1.AjaxRequest(); call.  Any ideas?
  8. Veselin Vasilev
    Admin
    Veselin Vasilev avatar
    2992 posts

    Posted 20 Aug 2008 Link to this post

    Hi Ryan,

    So, you are using the "classic" RadTreeView and the new RadAjaxManager? Why don't you use the new RadTreeView as well?

    You need to call ajaxRequest() instead of AjaxRequest() method.

    All the best,
    Veskoni
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
  9. Ryan
    Ryan avatar
    6 posts
    Member since:
    Aug 2008

    Posted 20 Aug 2008 Link to this post

    now i get this error '~/Telerik.Web.UI.WebResource.axd' is missing in web.config. RadScriptManager requires a HttpHandler registration in web.config. Please, use the control Smart Tag to add the handler automatically, or see the help for more information: Controls > RadScriptManager

    yet in my web.config file this is what i have

     <httpHandlers>
          <remove path="*.asmx" verb="*"/>
          <add path="*.asmx" verb="*" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" validate="false"/>
          <add path="*_AppService.axd" verb="*" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" validate="false"/>
          <add path="ScriptResource.axd" verb="GET,HEAD" type="System.Web.Handlers.ScriptResourceHandler, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" validate="false"/>
          <add path="*.asbx" verb="GET,HEAD,POST" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" validate="false"/>
          <add path="Telerik.Web.UI.WebResource.axd" verb="*" type="Telerik.Web.UI.WebResource, Telerik.Web.UI, Version=2008.2.723.20, Culture=neutral, PublicKeyToken=121fae78165ba3d4" validate="false"/>
          <remove verb="*" path="*.asmx"/>
          <add verb="*" path="*.asmx" validate="false" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
          <add verb="*" path="*_AppService.axd" validate="false" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
          <add verb="GET,HEAD" path="ScriptResource.axd" type="System.Web.Handlers.ScriptResourceHandler, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" validate="false"/>
        </httpHandlers>

    do you see anything wrong here?
  10. Ryan
    Ryan avatar
    6 posts
    Member since:
    Aug 2008

    Posted 20 Aug 2008 Link to this post

    Actually nevermind.  I realized i forgot to replace those httphandlers, i left them out so that i could just have it fill from the smart tag, but once i put them in place it ran thanks a lot!
  11. rupesh
    rupesh avatar
    2 posts
    Member since:
    Oct 2010

    Posted 14 Oct 2010 Link to this post

    Hi all,

    The GetXml is good and generating the xml without any problem but what if i wanted to short the nodes of XML pls help regarding this.
    U can better understand my requirement by going through this.
    http://www.telerik.com/community/forums/aspnet-ajax/treeview/how-to-short-nodes-in-redtreenode-after-pasting-a-node.aspx


    Thanks
    Rupesh  
  12. Yana
    Admin
    Yana avatar
    4554 posts

    Posted 19 Oct 2010 Link to this post

    Hi rupesh,

    Please check the forum thread  - we've already answered to your question there.

    Regards,
    Yana
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  13. Kartheek
    Kartheek avatar
    12 posts
    Member since:
    Dec 2010

    Posted 23 Feb 2011 Link to this post

    Hi,

    I am trying to implement the samething in Silverlight, is it possible RadTreeView.

    Thanks,
    Kartheek
  14. Yana
    Admin
    Yana avatar
    4554 posts

    Posted 24 Feb 2011 Link to this post

    Hello Kartheek,

    Could you please post your question in the Silverlight forum here? Thanks

    Best wishes,
    Yana
    the Telerik team
    Registration for Q1 2011 What’s New Webinar Week is now open. Mark your calendar for the week starting March 21st and book your seat for a walk through all the exciting stuff we ship with the new release!
  15. Kartheek
    Kartheek avatar
    12 posts
    Member since:
    Dec 2010

    Posted 24 Feb 2011 Link to this post

    I have posted the question in Silverlight forums and i am not getting any reply, so i have posted here.

    Please find the thread.
    http://www.telerik.com/community/forums/silverlight/treeview/save-the-treeview-state.aspx

    Thanks,
    Kartheek
  16. Yana
    Admin
    Yana avatar
    4554 posts

    Posted 25 Feb 2011 Link to this post

    Hi Kartheek,

    Please check the SilverLight forum again. Thanks

    Greetings,
    Yana
    the Telerik team
    Registration for Q1 2011 What’s New Webinar Week is now open. Mark your calendar for the week starting March 21st and book your seat for a walk through all the exciting stuff we ship with the new release!
  17. Ramakrishna
    Ramakrishna avatar
    8 posts
    Member since:
    Apr 2014

    Posted 02 Jul 2014 in reply to Veselin Vasilev Link to this post

    Hi Ryan.
    your approach is working well but it is costlier
    one coz we have 7 trees in a single page and those are divided by
    tabs. So how to do the same functionality without taking whole XML content into
    a session object.

    Thanks
    Rama.
  18. Ramakrishna
    Ramakrishna avatar
    8 posts
    Member since:
    Apr 2014

    Posted 07 Jul 2014 Link to this post

    I need help please !
    Stored expanded nodes in a Dictionary object and have to expand the parent and child nodes though page refresh happens.
    Below is the code ... Child nodes are expanding in LoadOnDemand for the first time.
    Private Shared dictOriginTree As New Dictionary(Of String, Boolean)

    Protected Sub rtvOriginTree_NodeExpand(sender As Object, e As RadTreeNodeEventArgs)        
            If Not dictOriginTree.ContainsKey(e.Node.UniqueID) Then
                dictOriginTree.Add(e.Node.UniqueID, e.Node.Expanded)
            End If
        End Sub

    Protected Sub ramMasterDocumentsAjaxManager_AjaxRequest(ByVal sender As Object, ByVal e As Telerik.Web.UI.AjaxRequestEventArgs)
    Dim node As RadTreeNode
                    For Each node In rtvOriginTree.GetAllNodes()
                        If dictOriginTree.ContainsKey(node.UniqueID) Then
                            node.ExpandParentNodes()
                            node.ExpandChildNodes()
                            node.Expanded = dictOriginTree.Item(node.UniqueID.ToString())
                            node.ExpandMode = TreeNodeExpandMode.ServerSide
                        End If
                    Next
    End Sub




  19. Hristo Valyavicharski
    Admin
    Hristo Valyavicharski avatar
    975 posts

    Posted 10 Jul 2014 Link to this post

    Hi Ramakrishna,

    You could try to use RadTreeView with RadPersistenceFramework. It allows you to preserve Selected, Checked and expanded nodes. Here is the online demo:

    http://demos.telerik.com/aspnet-ajax/treeview/examples/applicationscenarios/persisting-treeview-settings/defaultcs.aspx?product=persistenceframework

    Regards,
    Hristo Valyavicharski
    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.

     
  20. Ramakrishna
    Ramakrishna avatar
    8 posts
    Member since:
    Apr 2014

    Posted 10 Jul 2014 in reply to Hristo Valyavicharski Link to this post

    Hi Hristo,
    Thank you very much for your reply.I gone through the Demo and saw the code but in the code Session object being used. My questions are 
    1) Is it possible without using Session
    2) In my case i have total of 7 RadTreeView controls in a single page. So i should use 7 different Session objects ? Absolutely it will hit the performance.


        Protected Sub SaveButton_Click(sender As Object, e As EventArgs)
            Session("CustomPersistenceSettingsKey") = Me.Session.SessionID
            Dim fileId As String = Session("CustomPersistenceSettingsKey").ToString()
            LoadButton.Enabled = True
            RadPersistenceManager1.StorageProviderKey = fileId
            RadPersistenceManager1.SaveState()
        End Sub
  21. Hristo Valyavicharski
    Admin
    Hristo Valyavicharski avatar
    975 posts

    Posted 11 Jul 2014 Link to this post

    Hi Ramakrishna,

    I have replied to your question here:
    http://www.telerik.com/forums/radtreeview-save-expanded-state-without-session-object#JgMUUf6GEk-Uw20sHj-TyA

    Please do not write in different threads for the same question.

    There is no need to have 7 different session objects. We are using the session, because in the demo we need to identify the anonymous users who browse the page.

    Regards,
    Hristo Valyavicharski
    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.

     
  22. Shawa
    Shawa avatar
    2 posts
    Member since:
    Aug 2014

    Posted 22 Aug 2014 Link to this post

    Hi, I'm looking for help.
    I saw the demo posted before using the persistence framework but i can't seem to be able to make it work.
    I'm in a situation where I use a radtreeview as links sidebar in my webform, it's actually located in a master page.
    The treeview is populated with RadTreeView.LoadContentFile(); method loading it from an xml file.
    In which events should I put the load and save sessions?

    Thanks, regards
  23. Shawa
    Shawa avatar
    2 posts
    Member since:
    Aug 2014

    Posted 22 Aug 2014 in reply to Shawa Link to this post

    Sorry I forgot some missing informations, I need that the state is saved when the tree nodes state is modified and loaded when the page is redirected to another one or refreshed.
  24. Hristo Valyavicharski
    Admin
    Hristo Valyavicharski avatar
    975 posts

    Posted 27 Aug 2014 Link to this post

    Hi Shawa,

    The LoadState(); method should be called, when page is loaded, but after the tree is populated with data. 
    The SaveSate() method needs to be called, when you expand any node or when node is selected. Suitable events are NodeExpand and NodeClick.

    Regards,
    Hristo Valyavicharski
    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.

     
  25. Richard
    Richard avatar
    2 posts
    Member since:
    Aug 2014

    Posted 29 Aug 2014 in reply to Veselin Vasilev Link to this post

    I am sorry.  I am new to this forum and cannot find how to create a new post.  So, if you would be so kind to answer me in this thread. 
    My issue is very similar to what is discussed in this post.  However, it has some peculiarities.I have to maintain an old application which uses RadTreeView.  This RadTreeView is defined as a menu in a master page and repopulated in Page_Init event handler for the master page.  I need to save the current expansion state of the tree and preserve it when the tree is recreated.

    What makes my task difficult is that I do not have (or at least I do not know) an event when to catch and preserve the expansion status of the tree.  When tree is collapsed and/or expanded in the browser, I do not get the post back to save the status.  I cannot move the population of the tree from the master page Page_Init to Page_Load handler because it is used in Page_Load event of the content pages, which is triggered before Page_Load of the master page.

    So, here is my question: how without changing user's experience (by introducing some bogus link buttons) capture RadTreeView expansion status?

  26. Hristo Valyavicharski
    Admin
    Hristo Valyavicharski avatar
    975 posts

    Posted 03 Sep 2014 Link to this post

    Hi Richard,

    The PersistenceFramework is a server control and to use it you will have to make a full post back or at least an ajax call. It is possible to store the expanded and selected nodes in a cookie without making any postbacks. You will have to handle the OnClientNodeExpanded and OnClientNodeSelected events. In these events save the data you need in a cookie. This way you will always have the latest changes.

    Finally after you have selected and expanded nodes you will have to restore them somehow. This can be done in the pageLoad event.

    function pageLoad() {
       //Restore tree state from the cookie
    }

    I hope this helps.

    Regards,
    Hristo Valyavicharski
    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.

     
  27. Rama
    Rama avatar
    3 posts
    Member since:
    May 2014

    Posted 10 Sep 2014 Link to this post

    Hi,
    Is that possible to save state of RadTreeView using "RadPersistenceManager " when expand a node on-demand base ?
    I applied for one of the tree which is on-demand base using RadPersistenceManager  and its not working.

    Please confirm.

  28. Peter Filipov
    Admin
    Peter Filipov avatar
    1028 posts

    Posted 15 Sep 2014 Link to this post

    Hello Rama,

    The RadMersistenceManager applies state only to existing nodes. In case that the nodes are not loaded it is not possible to apply the saved state.

    Regards,
    Peter Filipov
    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.

     
  29. Rama
    Rama avatar
    3 posts
    Member since:
    May 2014

    Posted 15 Sep 2014 in reply to Peter Filipov Link to this post

    Thank you very much for your response.

    I would like to know is there any other ways to do it, not only using RadPersistenceManager.

    Thanks
    Ramakrishna.
  30. Peter Filipov
    Admin
    Peter Filipov avatar
    1028 posts

    Posted 18 Sep 2014 Link to this post

    Hello Rama,

    Our control does not support such API and it is not possible to do it out of the box. You will to implement it on your own.

    Regards,
    Peter Filipov
    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.

     
  31. Richard
    Richard avatar
    2 posts
    Member since:
    Aug 2014

    Posted 22 Sep 2014 in reply to Hristo Valyavicharski Link to this post

    Hristo,

    Thank you very much for your suggestion.  It was working fine... until I got a couple of menu options with the same text.
    Unfortunately menu nodes do not have unique IDs so I was identifying the nodes by text.  When there are more than one node with the same text, preserving the menu state becomes impossible.

    Would you have any suggestion on how to rectify this situation?
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017