Failed to load viewstate. The control tree into which viewstate is..

I got this error message when i was working with dynamic control earlier. It seems this exception is thrown when some control in the control tree can not successfully load it’s viewstate.

Let’s take a look at the code,

i created a dynamic list view, set the templates and add the listview to a placeholder control. So far everything works fine, i can add a data and it display it, delete also works but the problem arise when i tried to edit the item. Let’s take a look at the item template and edit template

It’s pretty straight forward, i have a literal control that display the value in view mode and a texbox control to display the value in edit mode. But everytime i try to edit it i got the same error again and again. And then a thought cross my mind.. what if i set all the controls in the item template and edit template but control their visibility property. Will that do the trick, let’s see..

Above is the modified item template, i include all controls that are used in both item template and edit template and basically just handle their visibility property. The edit template has simillar contruct but with different controls being hidden, you get the idea. And so.. compile, run the code.. fingers crossed.. and it works!. It has the same control hierarchy when on view mode and edit mode but display different controls, i guess using dynamic controls can be quite tricky.

Hope this helps.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.