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

Maintain State Between Callbacks?

8 Answers 348 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
rcbarth
Top achievements
Rank 1
rcbarth asked on 04 Mar 2008, 05:53 PM
I have a RadTreeView control inside an AJAX update panel. When various ajax methods on the server run, I repopulate the control from the data store. Is there a way to make the control remember it's expanded/collapsed state as well as what node was selected automatically?

It's relatively easy to do and I was wondering if I would have to do this manually or if I just missed a property on the control so that it maintains its state on its own.

The user experience of having the expanded/collapsed nodes default back to all collapsed or all expanded (if the developer issues an ExpandAllNodes() call on the server before return), and the selected node being no longer selected is very poor.

8 Answers, 1 is accepted

Sort by
0
Atanas Korchev
Telerik team
answered on 05 Mar 2008, 07:48 AM
Hi rcbarth,

RadTreeView should maintain automatically its state after being updated by ASP.NET Ajax. Please check the following example: http://www.telerik.com/demos/aspnet/prometheus/Controls/Examples/Integration/FileBrowser/DefaultCS.aspx

Regards,
Albert
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
rcbarth
Top achievements
Rank 1
answered on 05 Mar 2008, 06:01 PM
In that example, the RadTreeView doesn't sit inside an UpdatePanel. In my situation, I completely rebind the tree on the server in the callback.

On mine, the user may add, edit, and delete tree nodes. The nodes have more properties than just the text displayed in the tree. There are three buttons for the users to use: Add, Edit, and Remove. Upon clicking Add or Edit, a RadWindow is displayed permitted the add/edit of the node information, and upon clicking OK, a WebMethod call is made, the database is updated, and upon return from the WebMethod call on the client, another callback is made to the server to refresh the updatepanel the tree sits in, which completely rebinds the tree. Upon rebinding, all state information is lost.

I worked around this by saving the expanded property for every node right before the refresh on the server, and then restoring it to the newly-bound tree right after the refresh (all before returning to the client). I would, however, think that the tree could maintain its own state. Certainly it's possible since I do it outside the control (e.g. just save the state right before the databinding, and restore it after the databind).
0
Nikolay
Telerik team
answered on 06 Mar 2008, 08:10 AM
Hello rcbarth,

RadTreeView would remember its state if you did not rebind it. Once you rebuild the entire treeview structure, the expanded state is lost. The approach you found yourself is quite applicable in you case.

I hope that it is acceptable for you to proceed this way.

Regards,
Nick
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
Matthew
Top achievements
Rank 1
answered on 04 Apr 2008, 01:55 AM
I am also interested in having the tree maintain it's state, but between pages and without the use of the AJAX manager.  For example, I want to show the exact same tree on page1.aspx and page2.aspx and with the same nodes populated and expanded.  If the user clicks a link on page1.aspx that goes to page2.aspx, this scenario would apply.  I wasn't able to serialize the tree and store it in the session state to accomplish this.  Is there a way I can do this?

Thanks,
Matt
0
Nikolay
Telerik team
answered on 04 Apr 2008, 12:20 PM
Hello Matt,

You can use the approach described in the following help article:
The state is not persisted after URL navigation

Even though the article relates to RadTreeView Classic you can still use the same approach.

Hope this helps.

Regards,
Nick
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
Bill
Top achievements
Rank 2
answered on 15 Apr 2008, 06:50 PM
That doesn't work when you have a RadTreeView bound to a sqlDataSource Control on the page.

The radtreeview has no nodes in the page load event.

Any way to handle this situation?
0
Nikolay
Telerik team
answered on 18 Apr 2008, 11:06 AM
Hi Bill,

You can hook on the NodeBound event of the treeview and execute the same logic (described in the help article provided with my previous post) in the NodeBound event handler.

I hope this helps.

Kind regards,
Nick
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
AL
Top achievements
Rank 1
answered on 22 Jul 2009, 01:51 PM
Thanks rcbarth for posting the question and thank you NICK for this solution.

Hello Matt,

You can use the approach described in the following help article:
The state is not persisted after URL navigation

Even though the article relates to RadTreeView Classic you can still use the same approach.

Hope this helps.

Regards,
Nick
the Telerik team
Tags
TreeView
Asked by
rcbarth
Top achievements
Rank 1
Answers by
Atanas Korchev
Telerik team
rcbarth
Top achievements
Rank 1
Nikolay
Telerik team
Matthew
Top achievements
Rank 1
Bill
Top achievements
Rank 2
AL
Top achievements
Rank 1
Share this question
or