We have recently upgraded from WebGrid v4 to WebGrid v9. We have several grid pages that provide the initial structure/layout on the aspx side:

<iswebgrid:WebGrid ID="WebGrid1" runat="server"	OnInitializeDataSource="WebGrid1_InitializeDataSource" 	OnInitializeLayout="WebGrid1_InitializeLayout" 	OnInitializePostBack="WebGrid1_InitializePostBack" 
	OnPrepareDataBinding="WebGrid1_PrepareDataBinding">
	<RootTable DataKeyField="ID" Caption="Main">
		<Columns>
			<iswebgrid:WebGridColumn DataMember="ID" Visible="false" ShowInSelectColumns="No" />
			<iswebgrid:WebGridColumn DataMember="Name" Name="Name" Caption="Name" Width="120px" />
			<iswebgrid:WebGridColumn DataMember="Description" Name="Description" Caption="Description" Width="150px" />
			<iswebgrid:WebGridColumn DataMember="CreatedBy" Caption="Created By" Visible="false" Width="125px" /> 
			<iswebgrid:WebGridColumn DataMember="CreatedDate" Caption="Created Date" DataType="System.DateTime" Visible="false" DataFormatString="MM/dd/yyyy hh:mm tt" Width="120px" />
			<iswebgrid:WebGridColumn DataMember="ModifiedBy" Caption="Modified By" Visible="true" Width="125px" />
			<iswebgrid:WebGridColumn DataMember="ModifiedDate" Caption="Modified Date" DataType="System.DateTime" Visible="true" DataFormatString="MM/dd/yyyy hh:mm tt" Width="120px" />
		</Columns>
	</RootTable>
	<LayoutSettings>
		<ClientSideEvents OnRowContextMenu="HandleRowContextMenu" OnCellDblClick="HandleDoubleClick" OnColumnMove="columnMove" OnColumnResize="columnResize" />
	</LayoutSettings>
</iswebgrid:WebGrid>

 If the user does not have a Saved view (ie: they are looking at this page for the first time, or have not customized the grid in any way, the above works just fine). There are client events fired up for when columns are resized, moved, removed, added. Once these events hit, the layout XML is saved to the database and loaded when the user navigates to the page. The server side events to save/load the custom views are:

protected void WebGrid1_InitializeLayout(object sender, ISNet.WebUI.WebGrid.LayoutEventArgs e)
{
	oGridFunctions.LoadGridView(WebGrid1);
}

protected void WebGrid1_InitializePostBack(object sender, PostbackEventArgs e)
{
	e.CustomActionData = oGridFunctions.SaveGridView(e.Action, WebGrid1, e.XmlRequest);
}

 The Issue:

  • The description column for example, has a default value of visible=false.
  • I right click on the grid header, and add the "Description" field in the select columns. The InitializePostback event then saves the grid markup correctly to XML. Everything is working good, and it seems there are no problems.
  • I re-visit the page (full postback). InitializeLayout method is called to load the previously saved grid view. The correct structure is loaded.
  • NOW, if I move/resize/add/remove a column, the grid grabs the default asp tags from the aspx markup during the ajax call. All of the saved changes are reverted to the "templated" default fields on the aspx page. The grid is NOT retaining the table structure loaded in the InitializeLayout event.
My question is, how can I go about saving\loading this view correctly? Is this a bug introduced in newer versions of webgrid considering it worked fine in v4? We are loading/saving the grid transparently to the end user based on their actions (moving/resizing/adding/removing/etc). So a save/load button is not something we would want to impose on our users. Loading the table structure should override anything in the aspx markup, like it did in v4.

*Edit - oGridFunctions.LoadGridView and oGridFunctions.SaveGridView are simply wrappers around intersoft's SaveTableStructureToXml and LoadTablesStructureFromXml with the addition of saving\loading that XML from the database. There are also hundreds of pages like this in the solution, so simply "removing the markup from the aspx page" as stated in other posts on this forum is not a solution.