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

前提是你 提交于 2019-11-28 23:31:55
nunespascal

What is important when you are adding controls dynamically is on which event you are adding them.

If you added controls on events that occur after load, they will be part of the viewstate you send to the client.

You will have to add those controls again before LoadViewState is called.

If you run into cases where the decision of which controls to add is itself stored in the ViewState or the value of a control, then remember even before the ViewState is loaded, this data is available in Request.Params

Refer the asp.net page life cycle

Hooman

I just added EnableViewState="false" to my page placeholder and its gone. Hope it works for u as well.

Mark Macneil Bikeio

This Error Mainly Occurs during View state Change: From One Template To other Template like in case of Item Template, Edit Item Template, in Controls like Form View, List Views, Detail View, Grid View in ASP .net (all frameworks);

While Changing from control states say Item Template ---> Edit Template the followings were going to alter

1) Controls will change (its ID & states)

2) Its Positions will change.

While Transformation of view if any post back occurs you will get Error as

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

if you are using separate control for data-binding like (button,link_button_Image_button events) you will get this error reported !

To avoid this error >>> Once state changes from one template to other within method you call data source binding ( Don't call during click or any post backing events ).

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

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

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

Check if you have the binding method of the control directly in your page load event. This can cause this problem.

You can add new PlaceHolder per UserControls

OR

You can set enableviewstate=false on the control , if you dont need viewstate

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

I was refreshing the data source before setting new page index.


This is what I was doing wrong

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

This is the right way

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

I had the same issue. This issue was at client end but it didn't occur in my local system. After hours of googling, i had written EnableViewState="false" to my table tag in aspx page which has all the dynamic controls and then i removed all the viewstate variables and instead i created some hidden textboxes in the aspx page and accepted DB values into them in code behind and used them throughout my code. It then solved my problem. But still, i couldn't figure out what was exactly the problem.

This can happen if you override SaveViewState in your control but don't override LoadViewState.

In my case I was manipulating the .Text property of a asp:Literal on page load which was causing the issue. In all other cases this never caused me a viewstate error but in this particular case I was changing the .Text value to an html element.

The following caused the error:

<asp:Literal ID="SvgIcon" runat="server" />

SvgIcon.Text = "<svg version=\"1.1\" id=\"Layer_1\" bla bla />"

I was able to resolve the error by adding EnableViewState="false" explicitly to the control:

<asp:Literal ID="SvgIcon" runat="server" EnableViewState="false" />
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!