Expand nodes after PostBack

9 posts, 2 answers
  1. EET Group
    EET Group avatar
    28 posts
    Member since:
    Aug 2007

    Posted 19 Sep 2008 Link to this post

    I'm using ServerSideCallBack to load my huge product category tree, but after a PostBack (when a user clicks a category to see), the entire tree is reset.

    Is there any way that I can expand/recall those nodes which the user loaded/clicked before he made the PostBack? They of course think it's annoying that the tree doesn't "remember" which sub-category they are in.

    As I said it's a huge tree, so I don't see any other way than the Load-On-Demand method.
  2. Atanas Korchev
    Admin
    Atanas Korchev avatar
    8462 posts

    Posted 19 Sep 2008 Link to this post

    Hello Buffer,

    Our online example behaves correctly after postback. What could be different in your case?

    Regards,
    Albert
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
  3. EET Group
    EET Group avatar
    28 posts
    Member since:
    Aug 2007

    Posted 19 Sep 2008 Link to this post

    Hi Albert,

    Basically I have built my implementation exactly as your example. Only thing is, that to be able to actually use the tree, I make an url redirect on the end-nodes (non-expandable).

    I have made this using: radNode.NavigateUrl

    Just to cover every option, I have also tried using OnNodeClick, and do a redirect from the NodeEventArgs, but this yields the same result. The tree is reset on the "new" page.

    Is it possible to save the tree state across pages, i.e. in a Session object, and restore it from where you "left off"?
  4. Answer
    Atanas Korchev
    Admin
    Atanas Korchev avatar
    8462 posts

    Posted 19 Sep 2008 Link to this post

    Hello Buffer,

    Yes, it is possible. You can use the GetXml method to retrieve the treeview state in xml format and store it in session. Then you can use the LoadXml to retrieve the state of the treeview back from the session and populate it. You can store the xml during NodeClick and load it back in Page_Load.

    Regards,
    Albert
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
  5. EET Group
    EET Group avatar
    28 posts
    Member since:
    Aug 2007

    Posted 23 Sep 2008 Link to this post

    Thank you, this solved my problem.

    I had to make use of the following fix/hack though: http://www.telerik.com/help/aspnet-ajax/troubleshooting-load-on-demand-expand-on-server-side-node-click.html

    PS. Now I'm saving a huge XML-tree to the SessionState - do you have any advice for perhaps removing cached sub-trees that are not expanded? (are using single-expansion path.
  6. Atanas Korchev
    Admin
    Atanas Korchev avatar
    8462 posts

    Posted 23 Sep 2008 Link to this post

    Hi Buffer,

    The GetXml method returns the whole treeview state - all nodes and their properties are included. You cannot serialize only the expanded nodes by using GetXml.

    Regards,
    Albert
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
  7. EET Group
    EET Group avatar
    28 posts
    Member since:
    Aug 2007

    Posted 23 Sep 2008 Link to this post

    Thanks for your answers. I have just one final question.

    My top-nodes that have children all use ServerSideCallBack to fetch the children. This works great. Then I use OnNodeClick to handle the server-side GetXml to Session when I click the children (bottom of the tree). This triggers a PostBack.

    My problem is now, that once the parents have fetched the children using ServerSideCallBack, they also responds to the OnNodeClick postback. This gives me ugly "do nothing" postbacks if I click a parent node twice.

    Is there any way to cancel the postback of parent nodes so only the children generates a NodeClick server side?

    Thanks in advance.
  8. Answer
    Atanas Korchev
    Admin
    Atanas Korchev avatar
    8462 posts

    Posted 23 Sep 2008 Link to this post

    Hello Buffer,

    You can set the PostBack property of a RadTreeNode object to false to prevent it from posting back.

    Regards,
    Albert
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
  9. EET Group
    EET Group avatar
    28 posts
    Member since:
    Aug 2007

    Posted 23 Sep 2008 Link to this post

    Wow, that was easy! I thought it would have cancelled the ServerSideCallBack, but it works like a charm!!

    Thank you for excellent service - the tree now does everything I want :)
Back to Top