Link to home
Start Free TrialLog in
Avatar of gromul
gromul

asked on

Failed to load viewstate Bug

I'm getting the following error message:

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.

This happens when my search returns a datagrid with only one result, and then editing that item puts it out of the search scope: i.e. if searching by year 1999 returned just one article and I changed the year of article, click Search button again causes the error. It seems to be connected with turning off edit mode (OurDataGrid.EditItemIndex = -1) when the datagrid doesn't have any items. If I don't turn off edit mode in this specialized case (only one article returned, then changed), it works, but later searches may have one of the items in edit mode, although this shouldn't happen for new searches.

Any ideas?

Thanks.
ASKER CERTIFIED SOLUTION
Avatar of mmarinov
mmarinov

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of gromul
gromul

ASKER

Thanks Marinov.

I fixed it by checking if the datagrid is left empty in which case I don't turn off edit mode until next search.

Still, it seems kind of strange that it crashes if you try to turn off edit mode when datagrid doesn't have any items, but it saves edit item index if you don't turn edit mode off. If it's not a bug, it's a really strange design decision.