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

Dynamically adding nodes resulting in ViewState error

1 Answer 39 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Jason
Top achievements
Rank 1
Jason asked on 23 Oct 2009, 04:57 PM
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

1 Answer, 1 is accepted

Sort by
0
Jason
Top achievements
Rank 1
answered on 26 Oct 2009, 05:01 PM
I was able to resolve this by initializing the tree view with EnableViewState = false.  Before adding nodes, I set EnableViewState to true.
Tags
TreeView
Asked by
Jason
Top achievements
Rank 1
Answers by
Jason
Top achievements
Rank 1
Share this question
or