This is a migrated thread and some comments may be shown as answers.

RadTreeView save expanded state

34 Answers 695 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Ryan
Top achievements
Rank 1
Ryan asked on 11 Aug 2008, 05:19 PM
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!

34 Answers, 1 is accepted

Sort by
0
Veselin Vasilev
Telerik team
answered on 12 Aug 2008, 07:34 AM
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.
0
Ryan
Top achievements
Rank 1
answered on 12 Aug 2008, 01:42 PM
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?
0
Ryan
Top achievements
Rank 1
answered on 13 Aug 2008, 01:11 PM
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())
0
Veselin Vasilev
Telerik team
answered on 15 Aug 2008, 01:30 PM
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.
0
Ryan
Top achievements
Rank 1
answered on 20 Aug 2008, 01:26 PM
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?
0
Veselin Vasilev
Telerik team
answered on 20 Aug 2008, 03:29 PM
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.
0
Ryan
Top achievements
Rank 1
answered on 20 Aug 2008, 03:39 PM
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?
0
Ryan
Top achievements
Rank 1
answered on 20 Aug 2008, 03:46 PM
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!
0
rupesh
Top achievements
Rank 1
answered on 14 Oct 2010, 11:31 AM
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  
0
Yana
Telerik team
answered on 19 Oct 2010, 11:52 AM
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
0
Kartheek
Top achievements
Rank 1
answered on 24 Feb 2011, 01:28 AM
Hi,

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

Thanks,
Kartheek
0
Yana
Telerik team
answered on 24 Feb 2011, 09:06 AM
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!
0
Kartheek
Top achievements
Rank 1
answered on 24 Feb 2011, 09:35 AM
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
0
Yana
Telerik team
answered on 25 Feb 2011, 04:22 PM
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!
0
Ramakrishna
Top achievements
Rank 1
answered on 02 Jul 2014, 09:03 PM
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.
0
Ramakrishna
Top achievements
Rank 1
answered on 07 Jul 2014, 09:00 PM
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




0
Hristo Valyavicharski
Telerik team
answered on 10 Jul 2014, 07:46 AM
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.

 
0
Ramakrishna
Top achievements
Rank 1
answered on 10 Jul 2014, 07:59 PM
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
0
Hristo Valyavicharski
Telerik team
answered on 11 Jul 2014, 08:48 AM
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.

 
0
Shawa
Top achievements
Rank 1
answered on 22 Aug 2014, 08:34 AM
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
0
Shawa
Top achievements
Rank 1
answered on 22 Aug 2014, 08:37 AM
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.
0
Hristo Valyavicharski
Telerik team
answered on 27 Aug 2014, 08:56 AM
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.

 
0
Richard
Top achievements
Rank 1
answered on 29 Aug 2014, 09:03 PM
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?

0
Hristo Valyavicharski
Telerik team
answered on 03 Sep 2014, 03:58 PM
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.

 
0
Rama
Top achievements
Rank 1
answered on 10 Sep 2014, 03:33 PM
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.

0
Peter Filipov
Telerik team
answered on 15 Sep 2014, 08:55 AM
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.

 
0
Rama
Top achievements
Rank 1
answered on 15 Sep 2014, 03:48 PM
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.
0
Peter Filipov
Telerik team
answered on 18 Sep 2014, 08:57 AM
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.

 
0
Richard
Top achievements
Rank 1
answered on 22 Sep 2014, 01:19 PM
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?
0
Hristo Valyavicharski
Telerik team
answered on 24 Sep 2014, 11:35 AM
Hi Richard,

I would suggest that you try the following approach:
  • Enable the menu selection:
    <telerik:RadMenu runat="server" EnableSelection="true" ID="RadMenu1">
  • In the cookie store the item's text or value.
  • Use menu client api to find and select the item you want:
    function restoreSelectedItem() {
        //...
        var menu = $find('RadMenu1');
        var item = menu.findItemByText("Home");
        if (item != null) {
            item.select();
        }
    }

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.

 
0
Hana
Top achievements
Rank 1
answered on 27 Apr 2016, 02:41 PM
Hi

I have project use radtreeview to checkbox node and then save in SQL server as database but not working.

Please help me

see attachment.

0
Hana
Top achievements
Rank 1
answered on 27 Apr 2016, 02:54 PM

Hi

I have project to select from radtreeview and save in database, but the save button not working to save in sql server

I have role table, operation table and roleoperation table after check box from treeview and click save button in roleoperation table

but save button can not save from treeview.

see some image.

0
Hana
Top achievements
Rank 1
answered on 27 Apr 2016, 03:01 PM
Hi Dear all,
Please help me I am tired to search and not get the solution.
I have project to select from radtreeview and save in database, but the save button not working to save in sql server
I have role table, operation table and roleoperation table after check box from treeview and click save button in roleoperation table
but save button can not save from treeview.
or can contact by email: hana_alamri@yahoo.com
see some image.
0
Hristo Valyavicharski
Telerik team
answered on 28 Apr 2016, 12:07 PM
Hi Hana,

Please open new support ticket and attach sample project.

Thanks.

Regards,
Hristo Valyavicharski
Telerik
Do you need help with upgrading your ASP.NET AJAX, WPF or WinForms projects? Check the Telerik API Analyzer and share your thoughts.
Tags
TreeView
Asked by
Ryan
Top achievements
Rank 1
Answers by
Veselin Vasilev
Telerik team
Ryan
Top achievements
Rank 1
rupesh
Top achievements
Rank 1
Yana
Telerik team
Kartheek
Top achievements
Rank 1
Ramakrishna
Top achievements
Rank 1
Hristo Valyavicharski
Telerik team
Shawa
Top achievements
Rank 1
Richard
Top achievements
Rank 1
Rama
Top achievements
Rank 1
Peter Filipov
Telerik team
Hana
Top achievements
Rank 1
Share this question
or