Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
Viewstate is corrupted

When I reset the web data grid after resetting my form and data grid, I am unable to re-use my page again. I am getting an error that my viewstate is corrupted in the webdatagrid behaviors section.

Basically, I have a few drop-down combo boxes and a data grid. Based on a combination of factors, the web data grid is either editable or not editable. When the form is editable, it will define the columns and set up an editing core object, and add it to the data grid. 

When the user decides to restart/reset the page, to start over with their selections, the form becomes unusable, no events take place, and I get an error through the Chrome Console stating that the viewstate is corrupted.

Uncaught Sys.WebForms.PageRequestManagerServerErrorException: Sys.WebForms.PageRequestManagerServerErrorException: Infragistics.Web.UI.GridControls.Behaviors ViewState is corrupted.

This is what I do when I reset the datagrid:


if ((bool)Session["EditMode"] == true)
    dg.Behaviors.EditingCore.RowUpdating -= EditingCore_RowUpdating;
    dg.Behaviors.EditingCore.Enabled = false;
    dg.AutoGenerateColumns = true;
    dg.DataKeyFields = "";
    Session["EditMode"] = false;