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

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

Jos

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

Mike Hnatt

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,007
Latest member
obedient dusk

Latest Threads

Top