Problem with ViewState ?

J

Jarod

Hey
I change backColor of linkButton in my Page_Load:
lbDoSth.BackColor = Color.Red;

But I have multiView on this page. On one of the views I have detailsView.
When I add a new row a set Visible = false on this detailsView. And rebound
appropriate gridView. Then I press the button and I have exception:

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.
Description: An unhandled exception occurred during the execution of the
current web request. Please review the stack trace for more information
about the error and where it originated in the code.

Exception Details: 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.

Source Error:


An unhandled exception was generated during the execution of the
current web request. Information regarding the origin and location of the
exception can be identified using the exception stack trace below.


Stack Trace:


[HttpException (0x80004005): 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.]
System.Web.UI.Control.LoadViewStateRecursive(Object savedState) +484
System.Web.UI.Control.LoadChildViewStateByIndex(ArrayList childState)
+195
System.Web.UI.Control.LoadViewStateRecursive(Object savedState) +425
System.Web.UI.Control.LoadChildViewStateByIndex(ArrayList childState)
+195
System.Web.UI.Control.LoadViewStateRecursive(Object savedState) +425
System.Web.UI.Control.LoadChildViewStateByIndex(ArrayList childState)
+195
System.Web.UI.Control.LoadViewStateRecursive(Object savedState) +425
System.Web.UI.Control.LoadChildViewStateByIndex(ArrayList childState)
+195
System.Web.UI.Control.LoadViewStateRecursive(Object savedState) +425
System.Web.UI.Control.LoadChildViewStateByIndex(ArrayList childState)
+195
System.Web.UI.Control.LoadViewStateRecursive(Object savedState) +425
System.Web.UI.Control.LoadChildViewStateByIndex(ArrayList childState)
+195
System.Web.UI.Control.LoadViewStateRecursive(Object savedState) +425
System.Web.UI.Control.LoadChildViewStateByIndex(ArrayList childState)
+195
System.Web.UI.Control.LoadViewStateRecursive(Object savedState) +425
System.Web.UI.Control.LoadChildViewStateByIndex(ArrayList childState)
+195
System.Web.UI.Control.LoadViewStateRecursive(Object savedState) +425
System.Web.UI.Control.LoadChildViewStateByIndex(ArrayList childState)
+195
System.Web.UI.Control.LoadViewStateRecursive(Object savedState) +425
System.Web.UI.Control.LoadChildViewStateByIndex(ArrayList childState)
+195
System.Web.UI.Control.LoadViewStateRecursive(Object savedState) +425
System.Web.UI.Page.LoadAllState() +558
System.Web.UI.Page.ProcessRequestMain(Boolean
includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +2238





--------------------------------------------------------------------------------

Version Information: Microsoft .NET Framework Version:2.0.50727.42; ASP.NET
Version:2.0.50727.42

How should I persist the backColor of the linkButton ? The problem is only
after Inser/Edit in detailsView and re-bound of controls.
Jarod
 
C

Cowboy \(Gregory A. Beamer\)

Turn off the multiview panel as late in the stack as is possible. I would
have to look at where viewstate is applied, but the easiest is to use an
event after viewstate is applied before you make something invisible.

--
Gregory A. Beamer

*************************************************
Think Outside the Box!
*************************************************
Jarod said:
Hey
I change backColor of linkButton in my Page_Load:
lbDoSth.BackColor = Color.Red;

But I have multiView on this page. On one of the views I have detailsView.
When I add a new row a set Visible = false on this detailsView. And
rebound appropriate gridView. Then I press the button and I have
exception:

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.
Description: An unhandled exception occurred during the execution of the
current web request. Please review the stack trace for more information
about the error and where it originated in the code.

Exception Details: 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.

Source Error:


An unhandled exception was generated during the execution of the
current web request. Information regarding the origin and location of the
exception can be identified using the exception stack trace below.


Stack Trace:


[HttpException (0x80004005): 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.]
System.Web.UI.Control.LoadViewStateRecursive(Object savedState) +484
System.Web.UI.Control.LoadChildViewStateByIndex(ArrayList childState)
+195
System.Web.UI.Control.LoadViewStateRecursive(Object savedState) +425
System.Web.UI.Control.LoadChildViewStateByIndex(ArrayList childState)
+195
System.Web.UI.Control.LoadViewStateRecursive(Object savedState) +425
System.Web.UI.Control.LoadChildViewStateByIndex(ArrayList childState)
+195
System.Web.UI.Control.LoadViewStateRecursive(Object savedState) +425
System.Web.UI.Control.LoadChildViewStateByIndex(ArrayList childState)
+195
System.Web.UI.Control.LoadViewStateRecursive(Object savedState) +425
System.Web.UI.Control.LoadChildViewStateByIndex(ArrayList childState)
+195
System.Web.UI.Control.LoadViewStateRecursive(Object savedState) +425
System.Web.UI.Control.LoadChildViewStateByIndex(ArrayList childState)
+195
System.Web.UI.Control.LoadViewStateRecursive(Object savedState) +425
System.Web.UI.Control.LoadChildViewStateByIndex(ArrayList childState)
+195
System.Web.UI.Control.LoadViewStateRecursive(Object savedState) +425
System.Web.UI.Control.LoadChildViewStateByIndex(ArrayList childState)
+195
System.Web.UI.Control.LoadViewStateRecursive(Object savedState) +425
System.Web.UI.Control.LoadChildViewStateByIndex(ArrayList childState)
+195
System.Web.UI.Control.LoadViewStateRecursive(Object savedState) +425
System.Web.UI.Control.LoadChildViewStateByIndex(ArrayList childState)
+195
System.Web.UI.Control.LoadViewStateRecursive(Object savedState) +425
System.Web.UI.Page.LoadAllState() +558
System.Web.UI.Page.ProcessRequestMain(Boolean
includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +2238





--------------------------------------------------------------------------------

Version Information: Microsoft .NET Framework Version:2.0.50727.42;
ASP.NET Version:2.0.50727.42

How should I persist the backColor of the linkButton ? The problem is only
after Inser/Edit in detailsView and re-bound of controls.
Jarod
 
J

Jarod

Turn off the multiview panel as late in the stack as is possible. I would
have to look at where viewstate is applied, but the easiest is to use an
event after viewstate is applied before you make something invisible.

Can you give me more details best with examples how to do it ? Because I've
never turned off anything from stack... and it sounds a bit tricky for me.
Event after viewstate was applied... ok, but what's the event name and on
what object use it ?
Jarod
 

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,769
Messages
2,569,582
Members
45,065
Latest member
OrderGreenAcreCBD

Latest Threads

Top