Skip to content
March 12, 2011 / pauldundon

Changes to ViewState Lost

The Problem: You have a server control which stores some properties in viewstate. The code which creates this control sets these properties, but they are not restored on postback.

Possible Cause: Changes to viewstate are only tracked after the OnInit event. If you set viewstate-stored properties before this, the changes will not flag to the control that the viewstate needs to be saved. You will not notice this if you make changes to any viewstate-stored property after the OnInit event (as this will flag the need to save the viewstate), or if you store properties in viewstate by overriding SaveViewState rather than using the ViewState collection.

Possible Solutions: Ensure that your control is part of the control tree before setting viewstate-stored properties. Alternatively, store the property value in a member variable and override SaveViewState and LoadViewState.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: