Failed To Load Viewstate Error
Contents |
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies
Failed To Load Viewstate The Control Tree Into Which
of this site About Us Learn more about Stack Overflow the company httpexception (0x80004005): failed to load viewstate. Business Learn more about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges failed to load viewstate gridview edit Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 4.7 million programmers, just like you, helping each other. Join them; it only takes a
How To Debug Failed To Load Viewstate
minute: Sign up Failed to load viewstate. The control tree into which viewstate is being loaded up vote 6 down vote favorite 4 I am receiving the following error message after an HTTP POST on an ASP.NET form hosted inside a UserControl: Failed to load viewstate. The control tree into which viewstate is being loaded must match the control tree that was
System.web.httpexception: Failed To Load Viewstate.
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. Here's additional info: I'm running .NET 4.5 RC It's an Umbraco 4.7-based website On my local dev machine the form works perfectly This error only occurs on the staging server which has .NET 4.5 (only), MSSQL 2012 Express, IIS 7.5, Windows 7 (I know, it's not a real server yet, one day maybe...) The server is not part of a web farm (or garden, tho that should be irrevelant) The user control does render controls dynamically I have applied all the latest service packs. I have run out of ideas now! I have even restarted it and also performed a richual over the server involving a song and a special dance to no avail. Thanks for any assistance or ideas! asp.net .net umbraco .net-4.5 asp.net-4.5 share|improve this question asked Aug 3 '12 at 12:44 krisdyson 1,91753373 this blog post helped me with most of my viewstate problems weblogs.asp.net/infinitiesloop/arch
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn more about Stack Overflow the company Business Learn more about hiring enableviewstate="false" developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question
Viewstatemodebyidattribute
x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 4.7 million programmers, just like you, helping each other. Join them; asp.net enableviewstate it only takes a minute: Sign up Failed to load viewstate error after moving website to a new server up vote 0 down vote favorite I don't really know where to start with this one. I am getting: `Failed to http://stackoverflow.com/questions/11795994/failed-to-load-viewstate-the-control-tree-into-which-viewstate-is-being-loaded 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.` after moving a website to a new server. The exact same code works on my other server. It happens when I submit one of my forms (but http://stackoverflow.com/questions/10008013/failed-to-load-viewstate-error-after-moving-website-to-a-new-server doesn't do it on all form submissions). Any ideas what can cause this so I have somewhere to look? Using: ASP.NET 2. EDIT: I am adding some user controls to a placeholder dynamically at runtime but this same code is working ok on my other server. I have tried clearing the controls in the place holder before adding new ones (as I saw a post about that) but it hasn't helped. EDIT2: It seems that the postback is just failing. It isn't going into the onClick code of the button either so something is deffintiely screwy .. If I try / catch the exception it seems that all the controls are still added successfully ... Setting my Dynamic UC's to EnableViewState = false resolves this particular error. EDIT3: Ok, I think I may have a handle on what is happening. For some reason on the old server the form action is default.aspx?action=amend but the new server is showing amend.html?action=amend so I think the re-write module is messing up in IIS. This would explain the control adding issue as well because the action is happening 2 times (I think). I will look into the Rewrite module and see if anything is wrong then post back. asp.net iis share|improve this question edited Apr 4 '12 at 10:23 asked Apr 4 '12 at 9:02 webnoob 7,259747104 Both servers have the same version of .NET? I've found some case
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 http://blog.typps.com/2008/01/failed-to-load-viewstate-typical.html initial request. The only way to resolve is a proper understanding of viewstate.http://geekswithblogs.net/FrostRed/archive/2007/02/17/106547.aspxis a interesting post on viewstate that i happen to read today, pointed out to me by someone who ran into a viewstate problem about the control tree not matching and was clearly afraid of adding controls dynamically after reading some facts presented in that article. Who wouldn't ?While the post gives us a very good understanding of viewstate and how it can fail, so i encourage you failed to to read it first, might seem lengthy but I assure you, it's quite interesting. However, when you're done, follow my rant here, since I feel it's important to know, that, the failure can only happenwhen either donedeliberately as per the sample code in the post i linked to above orto *not* understanding viewstate and how it works.So how can we easily avoid these failures ? Let's look at his first code example,and build onto that :protected void Page_Init(object sender, EventArgs failed to load e){ if (!IsPostBack) { Button btnClickMe = new Button(); form1.Controls.Add(btnClickMe); btnClickMe.Text = "Click me"; } else { Label label = new Label(); form1.Controls.Add(label); }}As you can note above, this is problematic, since the control into which viewstate is restored is matched by control index, so when the index changes, as is clear in the above code, because if btnClickMe was loaded in for example index [0], now upon postback, after the page has been recreated and rebuilt, the Label "label" is loaded in index [0] instead and takes the place of the button. So this means viewstate that was meant for the button is loaded into the label instead, and the output in the screen after clicking the button is "click me" which was clearly not provided to the label's text property.Now that we understand the problem, how can this sample apply in real world or why would anybody want to do something like this ? Basically in short, why is viewstate being utilized, if it's not needed after postback ? Button btnClickMe is not reloaded after postback, so it's safe to turn off viewstate on this control, and problem is solved.This is a typical situation where you deliberately want viewstate to fail, apart from that i see no real use to want to maintain viewstate, which is also bloat on a control that clearly is not utilizing it.so a rewrite ? here : protected void Page_Init(object sender,