ViewState problem/question when making minor tweaks to a pagehttp://forums.asp.net/t/1842433.aspx/1?ViewState+problem+question+when+making+minor+tweaks+to+a+pageTue, 11 Sep 2012 22:12:37 -040018424335141603http://forums.asp.net/p/1842433/5141603.aspx/1?ViewState+problem+question+when+making+minor+tweaks+to+a+pageViewState problem/question when making minor tweaks to a page <p>I'm using .NET 3.5/C#</p> <p>I have a web page that creates dynamic TreeView controls and uses the ViewState. The dynamic controls are recreated on postbacks.</p> <p>The page has worked fine for a couple years.</p> <p>There are 2 non-dynamic controls at the top of the page (CheckBoxList and RadioButtonList)</p> <p>I went in today&nbsp;and made the CheckBoxList wider and change the order of the items. Those were the only changes. No c# changes, just two design-time changes to a non-dynamic CheckBoxList</p> <p>Now when I run the application I get a ViewState error when recreating my dynamic TreeView controls</p> <p>huh??</p> <p>Failed to load viewstate.&nbsp; The control tree into which viewstate is being loaded must match the control tree that was used to save viewstate during the previous request.&nbsp; 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.</p> <p>I can recreate the problem. I got the old version of the page from sourcecode control, made just those two change and wammo the error shows up.</p> <p>What's funny is I get the viewstate error when trying to add a dynamic Literal to a Panel (it goes between each dynamic TreeView)</p> <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; panelLeft.Controls.Add(l);</p> <p>can anyone explain to me what's going on?</p> <p>thanks</p> <p>mike</p> <p>&nbsp;</p> <p>&nbsp;</p> <p>&nbsp;</p> <p>&nbsp;</p> 2012-09-11T19:49:56-04:005141678http://forums.asp.net/p/1842433/5141678.aspx/1?Re+ViewState+problem+question+when+making+minor+tweaks+to+a+pageRe: ViewState problem/question when making minor tweaks to a page <p>Just got a huge clue.</p> <p>I went back to the working page and made the changes to the non-dynamic control 1 at a time and it never busted the page</p> <p>Then I realized, I've been typing a lot of my aspx code in the pages lately and have gotten in the habbit of running Visual Studio's &quot;Format Document&quot;</p> <p>I ran &quot;Format Document&quot; and sure enough that is what busts the page/viewstate</p> <p>now at least I can do a diff with the working copy to try and figure out what changes are made by &quot;Format Document&quot; that are busting the viewstate</p> <p>&nbsp;</p> 2012-09-11T22:12:37-04:00