Failed to load viewstate

  • Thread starter Thread starter Sanjay Pais
  • Start date Start date
S

Sanjay Pais

We keep getting this error on one of our web pages. I have absolutely no
idea which control is causing the problem. How do i diagnose and fix this
problem?



It has been driving us nuts!



Thanks



Sanjay



System.Web.HttpException: 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.

at System.Web.UI.Control.LoadViewStateRecursive(Object savedState)

at System.Web.UI.Control.LoadChildViewStateByIndex(ArrayList childState)

at System.Web.UI.Control.LoadViewStateRecursive(Object savedState)

at System.Web.UI.Control.LoadChildViewStateByIndex(ArrayList childState)

at System.Web.UI.Control.LoadViewStateRecursive(Object savedState)

at System.Web.UI.Control.LoadChildViewStateByIndex(ArrayList childState)

at System.Web.UI.Control.LoadViewStateRecursive(Object savedState)

at System.Web.UI.Control.LoadChildViewStateByIndex(ArrayList childState)

at System.Web.UI.Control.LoadViewStateRecursive(Object savedState)

at System.Web.UI.Control.LoadChildViewStateByIndex(ArrayList childState)

at System.Web.UI.Control.LoadViewStateRecursive(Object savedState)

at System.Web.UI.Control.LoadChildViewStateByIndex(ArrayList childState)

at System.Web.UI.Control.LoadViewStateRecursive(Object savedState)

at System.Web.UI.Control.LoadChildViewStateByIndex(ArrayList childState)

at System.Web.UI.Control.LoadViewStateRecursive(Object savedState)

at System.Web.UI.Control.LoadChildViewStateByIndex(ArrayList childState)

at System.Web.UI.Control.LoadViewStateRecursive(Object savedState)

at System.Web.UI.Control.LoadChildViewStateByIndex(ArrayList childState)

at System.Web.UI.Control.LoadViewStateRecursive(Object savedState)

at System.Web.UI.Control.LoadChildViewStateByIndex(ArrayList childState)

at System.Web.UI.Control.LoadViewStateRecursive(Object savedState)

at System.Web.UI.Control.LoadChildViewStateByIndex(ArrayList childState)

at System.Web.UI.Control.LoadViewStateRecursive(Object savedState)

at System.Web.UI.Page.LoadAllState()

at System.Web.UI.Page.ProcessRequestMain(Boolean
includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
 
Essentially, the framework pulls the viewstate and starts matching controls
to their viewstate values. You might then have new values from the submit,
which overrides these values. Then viewstate is reset.

By design, it fails if it has a value that does not match a control. This is
most common with dynamically added controls. That leads to this question:

Are you using dynamically added controls? If so, you have to place them on
the page before ViewState is pulled by the CLI ... IF they use viewstate on
these controls, that is.

--
Gregory A. Beamer
MVP, MCP: +I, SE, SD, DBA

Subscribe to my blog
http://gregorybeamer.spaces.live.com/lists/feed.rss

or just read it:
http://gregorybeamer.spaces.live.com/

*************************************************
| Think outside the box!
|
*************************************************
 
generally this happens when on postback, controls do not get the same id as
on the original render. this is caused by having server controls with no id
specified (so the id is generated). then postback logic causes the controls
to be created in a different order, so the ids do not match the render ids.

check for <% if %> on the asp page

-- bruce (sqlwork.com)
 
Back
Top