Maintain State Between Callbacks?

9 posts, 0 answers
  1. rcbarth
    rcbarth avatar
    13 posts
    Member since:
    Dec 2006

    Posted 04 Mar 2008 Link to this post

    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.
  2. Atanas Korchev
    Admin
    Atanas Korchev avatar
    8462 posts

    Posted 05 Mar 2008 Link to this post

    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
  3. rcbarth
    rcbarth avatar
    13 posts
    Member since:
    Dec 2006

    Posted 05 Mar 2008 Link to this post

    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).
  4. Nikolay
    Admin
    Nikolay avatar
    3997 posts

    Posted 06 Mar 2008 Link to this post

    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
  5. Matthew
    Matthew avatar
    51 posts
    Member since:
    Nov 2007

    Posted 03 Apr 2008 Link to this post

    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
  6. Nikolay
    Admin
    Nikolay avatar
    3997 posts

    Posted 04 Apr 2008 Link to this post

    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
  7. Bill
    Bill avatar
    85 posts
    Member since:
    Oct 2007

    Posted 15 Apr 2008 Link to this post

    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?
  8. Nikolay
    Admin
    Nikolay avatar
    3997 posts

    Posted 18 Apr 2008 Link to this post

    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
  9. AL
    AL avatar
    40 posts
    Member since:
    May 2008

    Posted 22 Jul 2009 Link to this post

    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
Back to Top