Viewstate error on second postback to page

  • Thread starter Thread starter Chris Thompson
  • Start date Start date
C

Chris Thompson

I have a page that uses a custom object I wrote to build a table. I also
have a post back to the page to remove items from that table. When the page
loads I can see the viewstate code on the source of the page is about 5
lines. When I post back to remove an item and rebuild the page it works. I
view the source of the page and the viewstate code has doubled in size even
though I have less data for it to hold. On the second post back I get "The
viewstate is invalid for this page and might be corrupted."

I get this error even if I turn off view state for the table that is being
rebuilt. Any thoughts on what is happening? I can provide more detail if
needed. Also, this code is running locally on my PC. There is no issue
with the transfer between webservers.
 
Chris Thompson said:
I have a page that uses a custom object I wrote to build a table. I also
have a post back to the page to remove items from that table. When the page
loads I can see the viewstate code on the source of the page is about 5
lines. When I post back to remove an item and rebuild the page it works. I
view the source of the page and the viewstate code has doubled in size even
though I have less data for it to hold. On the second post back I get "The
viewstate is invalid for this page and might be corrupted."

I get this error even if I turn off view state for the table that is being
rebuilt. Any thoughts on what is happening? I can provide more detail if
needed. Also, this code is running locally on my PC. There is no issue
with the transfer between webservers.

Chris, if you turn on page tracing, you'll find that it will show you the
control hierarchy, along with the viewstate size each control is
contributing.

This sort of thing happens when the control hierarchy changes between
postbacks. At the beginning of a subsequent request, you first want to
reconstruct the same control hierarchy which existed at the end of the
previous request. This control hierarchy can then consume the same ViewState
which it created at the end of the previous request. Only then can you
change the control hierarchy by adding or removing controls.

This changed hierarchy can then produce viewstate. At the beginning of the
next request, you'll rebuild the control hierarchy as it was at the end of
this request ...
 
Hi,

Thanks for the reply. I'm a little confused on the control hierarchy.
How is it that I can control/change this between requests?
 
Chris Thompson said:
Hi,

Thanks for the reply. I'm a little confused on the control hierarchy.
How is it that I can control/change this between requests?

The term "Control hierarchy" (or better, "Control Tree") refers to which
controls contain which other controls in their "Controls" collection. It can
be changed by doing things like dynamically adding or removing controls.
 
Back
Top