Failed to load viewstate

  • Thread starter Thread starter David
  • Start date Start date
D

David

I am working on project which is written by my former collegue

I got the following exception:
"Failed to load viewstate. The control tree into which viewstate is being
loaded much matech the control tree that was used to save during the
previous request. For example , when adding controls dynamically, the
controls added during a post-back must match poisition of the controls added
during initial request"

This exception is not consistent. Users reported that it happen sometimes
but not all the time.

I know. the page add some control dynamically but I did not have chance to
look at it in detail yet.

Does anybody have any suggestion from where I should start to look?
 
As you probably know, viewstate restores values based on the IDs of contorls
during postback. In order for this to work, ViewState expects the contorl
tree to be the same before and after. The error basically tells you that
the control tree is got on postback wasn't the same as before. Since you
are using dynamic controls, make sure to give them an explicit ID, and to
make sure htey are recreated on postback with those same IDs.

Since you haven't looked into this yet youhaven't really provided much
detail, hence my general answer.

Karl
 
Thank you very much for your reply.

I made some changes in the code. Whenever I add a new control I give the
control an ID. Currently it seem like it works. I will keep watching

Thanks
 
Actually, this gave me a great start, because that was exactly the problem,
it was loading controls incorrectly.

Thanks!
 
Back
Top