Home - Forums-.NET - FlyTreeView (ASP.NET) - "Failed to load ViewState" error

FlyTreeView (ASP.NET)

Technical support and KB related to the FlyTreeView control

This forum related to following products: FlyTreeView for ASP.NET

"Failed to load ViewState" error
Link Posted: 21-Jun-2009 16:11
I was hoping FlyTreeView might make it easier to get around this one, but not yet...

I have a page with a treeview on the left side, which gets populated in code with several different types of item from a database.  There can be up to 6 levels in the treeview.  The idea is that when the user selects an item in the tree by clicking it, details of that item appear in a DetailsView on the right.  They can edit item details, and also add new items or delete them (at leaf level).  All fine so far.

But there is one scenario that is causing the problem - one type of item can be edited in a way that causes it to move to a different part of the tree, so effectively the structure of the treeview changes, not at leaf level.  The edit happens and the treeview gets repopulated and redisplayed correctly, but the next time an item is selected - boom, the "Failed to load viewstate" exception ( I have PostBackOnSelect set true for most nodes).  I thought maybe I could set EnableViewState=false, but if I do that I don't even get the NodeSelected events fired.  I can sort of understand what is happening here, but can't see a way around it.  I need to be able to support this function in the system, i.e. I need to get the edited details on a postback, and I need to be able to repopulate the tree in the new structure.  Is this possible?  If so, how do I need to go about it?  This is making my brain hurt!
Link Posted: 22-Jun-2009 00:04
So first you need to know why you get "Failed to load ViewState" exception.
Do you use UpdatePanels?
Can you send a simple test page that reproduces the error? So we can debug it and see how to solve the problem.
Link Posted: 22-Jun-2009 13:05
Thanks.  I am not using UpdatePanels - perhaps I should be.  I am not suggesting this is a problem with FlyTreeview.  I had the same problem with the built-in ASP.NET treeview, and hoped FlyTreeview might have a way around it.  I have almost concluded that what I want to do simply can't be done in ASP.NET, because of the order in which things happen.  The problem appears to be that dynamic controls (like my treeview, which can change all the time) need to be rebuilt early in the page life cycle, probably the Init event.  But the events fired from other controls which can update the treeview don't get fired until AFTER that.  So I have already built the treeview by the time I get the event that needs to change it, and will always be one cycle behind.  That's how it appears to me anyway - I'd love to be convinced otherwise!  Maybe I could/should to do more of this in Javascript on the client side, but I'm not strong in that area. My real page is way too big to post - if I get time I will make up a small one to illustrate this.
Link Posted: 23-Jun-2009 02:56
Many thanks for the heads-up on UpdatePanels.  I have incorporated a couple of UpdatePanels on my page, and it is now doing what I want it to do, and even more smoothly, because I now have partial page refreshes.  Fabulous!

I believe the problem I was having was actually nothing to do with the TreeView directly, but something else I was doing to get it (and the page) to refresh correctly at appropriate times.  With the UpdatePanels I have now reworked the refresh mechanisms completely.  It's a very complex page, so I won't try to explain it all.  I have reverted to the standard ASP.NET Treeview, but since it now seems to work OK I will try the FlyTreeview again, because it looks better and appears to have better functionality.

Thanks again.