Dynamically adding nodes resulting in ViewState error

2 posts, 0 answers
  1. Jason
    Jason avatar
    13 posts
    Member since:
    Sep 2006

    Posted 23 Oct 2009 Link to this post

    I have a RadTreeView declared on an .ascx page.  All nodes are dynamically added later on a postback.  I'm getting the following error:

    Failed to load viewstate.  The control tree into which viewstate is being loaded must match the control tree that was used to save viewstate during the previous request.  For example, when adding controls dynamically, the controls added during a post-back must match the type and position of the controls added during the initial request.

    I'm able to get around this in the case where I will always have just one root node by adding a dummy node to the tree view on the initial load of the page, then clearing that node prior to adding the actual root node followed by its children.  I'm not able to get around it though in the case where I have multiple root nodes, because the number of root nodes depends on some user selections prior to a postback where the nodes are loaded.

    I did just upgrade to the AJAX controls from the classic controls, and I was not having this problem with the classic controls.

    Thanks,
    Jason

  2. Jason
    Jason avatar
    13 posts
    Member since:
    Sep 2006

    Posted 26 Oct 2009 Link to this post

    I was able to resolve this by initializing the tree view with EnableViewState = false.  Before adding nodes, I set EnableViewState to true.
Back to Top