Failed to load viewstate
- by Jen
OK have just started getting this error and I'm not sure why. I have a hosting page which has listview and a panel with a usercontrol. The listview loads up records with a linkbutton. You click the link button to edit that particular record - which gets loaded up in the formview (within the usercontrol) which goes to edit mode. After an update occurs in the formview I'm triggering an event which my hosting page is listening for. The hosting page then rebinds the listview to show the updated data. So this all works - but when I then go to click on a different linkbutton I get the below error:
Webpage error details
User Agent: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; WOW64; Trident/4.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; InfoPath.3)
Timestamp: Fri, 18 Jun 2010 03:15:54 UTC
Message: Sys.WebForms.PageRequestManagerServerErrorException: Failed to 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.
Line: 4723
Char: 21
Code: 0
URI: http://localhost:1951/AdminWebSite/ScriptResource.axd?d=yfdLw4zYs0bqYqs1arL-htap1ceeKCyW1EXhrhMZy_AqJ36FUpx8b2pzMKL6V7ebYsgJDVm_sZ_ykV1hNtFqgYcJCLLtardHm9-yyA7zC4k1&t=ffffffffec2d9970
Any suggestions as to what is actually wrong??
My event listener does this:
protected void RatesEditDate1_EditDateRateUpdated()
{
if (IsDateRangeValid(txtDisplayFrom, txtDisplayTo))
{
PropertyAccommodationRates1.DataBind();
}
else
{
pnlViewAccommodationRates.Visible = false;
}
divEditRate.Visible = false;
}
When I click my link button - it should be hitting this but the second time round it errors before hitting the breakpoint:
protected void RatesEditDate1_EditDateRateSelected(DateTime theDateTime)
{
// make sure everything else is invisible
pnlAddAccommodation.Visible = false;
pnlViewEditAccommodations.Visible = false;
RatesEditDate1.TheDateTime = theDateTime;
RatesEditDate1.PropertyID = (int)Master.PropertyId;
if (!String.IsNullOrEmpty(Accommodations1.SelectedValue))
{
RatesEditDate1.AccommodationTypeID = Convert.ToInt32(Accommodations1.SelectedValue);
}
else
{
RatesEditDate1.AccommodationTypeID = 0;
}
divEditRate.Visible = true;
}
So my listview appears to be being rebound successfully - I can see my changed data.. I just don't know why its complaining about viewstate when I click on the linkbutton. Or is there a better way to update the data in my listview? My listview and formview are bound to objectdata sources (in case that matters)
Thanks for the help!