protected void btnSave_Click(object sender, EventArgs e) { Session["Layout"] = ASPxPivotGrid1.SaveLayoutToString(PivotGridWebOptionsLayout.DefaultLayout); MemoryStream collapseStateStream = (MemoryStream)(Session["CollapseStateStream"]); if (collapseStateStream != null) { collapseStateStream.Dispose(); } collapseStateStream = new MemoryStream(); ASPxPivotGrid1.SaveCollapsedStateToStream(collapseStateStream); Session["CollapseStateStream"] = collapseStateStream; }