Failed to load viewstate. The control tree into which viewstate is loaded

I get the following error message after an HTTP POST in an ASP.NET form hosted inside a UserControl:

Failed to load viewstate. The control tree into which the viewstate is loaded must correspond to the control tree that was used to save the view state during the previous request. For example, when adding controls dynamically, controls added during feedback should match the type and position of controls added during the initial request.

Here is additional information:

  • I am running .NET 4.5 RC
  • This is a Umbraco 4.7 based website.
  • On my local dev machine, the form works fine
  • This error occurs only on an intermediate server with .NET 4.5 (only), MSSQL 2012 Express, IIS 7.5, Windows 7 (I know this is not a real server yet, maybe one day ...)
  • The server is not part of the web farm (or garden, which should be invulnerable).
  • User control dynamically displays controls

I applied all the latest service packs. Now I'm out of ideas! I even restarted it, and also performed a rich server-based song and a special dance to no avail.

Thanks for any help or ideas!

+8
source share
10 answers

OK, so the answer is literally: "Set up a new server with all the same software as the last and try again," and now it works.

+1
source share

What is important when dynamically adding controls to which event you add them.

If you add controls for events that occur after loading, they will be part of the view state that you send to the client.

You will need to add these controls before calling LoadViewState .

If you are faced with situations where the decision about which controls to add is itself stored in the ViewState or the value of the control, and then remember before loading the ViewState , this data is available in Request.Params

Refer asp.net page life cycle

Page life cycle

+18
source share

I just added EnableViewState="false" to my page placeholder and it went away. Hope it works for you too.

+16
source share

This error mainly occurs during view state. Change: from one template to another template, for example, in the case of an element template, editing the element template in controls, such as form view, list view, detailed view, grid view in ASP.net (all frames);

While a change from the control states says Item Template ---> Edit Template following changes have changed

1) The controls will change (its identifier and state)

2) His position will change.

While view transformation, if any mail back, you will get Error as

Failed to load viewstate. The management tree into which to load ....

if you use a separate control for data binding (for example, button_button_Image_button events), you will get this error!

To avoid this error →> As soon as the state changes from one template to another in the method, you call the data source binding (do not call during post clicks or any post posting events).

+3
source share

I add the attribute "name" with the same value as id, then this problem disappeared.

 <input type="button" id="extractBomInfoBtn" name="extractBomInfoBtn" value="Extract" class="button textonly" /> 
0
source share

Check if you have a method to bind the control directly in the page load event. This may cause this problem.

0
source share

You can add a new PlaceHolder for UserControls

OR

You can set enableviewstate=false on the control if you don't need viewstate

0
source share

In my case, I had a grid view with an event (OnPageIndexChanging) and when I click on the page, nothing will happen until I click twice!

I updated the data source before setting a new page index.


This is what I did wrong

 grd.DataSource = data; grd.DataBind(); grd.PageIndex = e.NewPageIndex; 

This is the right way.

 grd.PageIndex = e.NewPageIndex; grd.DataSource = data; grd.DataBind(); 
0
source share

I had the same problem. This problem was on the client side, but it did not happen on my local system. After hours of working on Google, I wrote EnableViewState = "false" in my table tag on an aspx page that has all the dynamic controls, and then I deleted all viewstate variables and instead created some hidden text fields on the aspx page and the accepted DB values in them in the code behind and used them in all my code. Then he solved my problem. But still I could not understand what the problem was.

0
source share

This can happen if you override SaveViewState in your control but do not override LoadViewState .

0
source share

All Articles