Failed to load viewstate (i.e., I'm doomed).

  • Thread starter Thread starter Mike Hnatt
  • Start date Start date
M

Mike Hnatt

I normally try to post more helpful subject lines. But in this case, after
tons of development, my app suddenly works no more.
Here is the message: I get this on the page postback when it dynamically
builds the controls based on the value I select in a drop-down list. It is
inconsistent. Sometimes the exact same process works, and sometimes it
doesn't. BTW, my drop-down list determines the control layout.
Any help would be majorly appreciated.

"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. "
 
Mike said:
I normally try to post more helpful subject lines. But in this case,
after tons of development, my app suddenly works no more.
Here is the message: I get this on the page postback when it
dynamically builds the controls based on the value I select in a
drop-down list. It is inconsistent. Sometimes the exact same
process works, and sometimes it doesn't. BTW, my drop-down list
determines the control layout.
Any help would be majorly appreciated.


"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. "

On postback, you have to make sure that exactly the same dynamic
controls are built (same name and number) as before the postback
(preferably in Page_Load), EVEN IF YOU DON'T WANT THEM TO
APPEAR ON YOUR PAGE ANYMORE.

Only then the necessary control postback events can fire.

In the handlers for these events, you can then rebuild your page
by destroying any unwanted controls and by adding new ones.
 
Thanks Jos,
I will try that. I just can't seem to understand why it worked fine for
hundreds of times until now. I'm sure it is something though. Thanks for
the help!
Mike
 
Back
Top