This is a migrated thread and some comments may be shown as answers.

Cannot Load View State when edit form is opened

1 Answer 89 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Lasly
Top achievements
Rank 1
Lasly asked on 25 Jan 2011, 06:13 PM

Hi,

I've problem with my radgrid.

My page add columns to Radgrid at runtime mode.

I've fired the Page_Init event and i'm able to add columns.

After edit or insert a record into my ragrid, if I don't close the edit form and do a postback with another control (in this case a RadTab control), who a different datasource (with more or less columns) my page catch an exception: "unable to load view state".

If I close the edit form page works correctly.

How can I resolve this problem?

<telerik:RadAjaxPanel ID="pnlElenco" runat="server" Height="100%" Width="100%">
                    <asp:Label ID="lblStato" runat="server" Width="100%" CssClass="statusbar_silver" />
                    <telerik:RadGrid ID="grdElenco" runat="server" AutoGenerateColumns="true" Width="100%"
                        AllowAutomaticUpdates="true" AllowAutomaticDeletes="true" AllowAutomaticInserts="true"
                        OnInsertCommand="OnInsertCommand" OnUpdateCommand="OnUpdateCommand" OnDeleteCommand="OnDeleteCommand"
                        OnNeedDataSource="NeedDataSource" Skin="Default" PageSize="15" OnColumnCreated="OnColumnCreated">
                        <PagerStyle AlwaysVisible="false" Mode="NextPrev" />
                        <ExportSettings ExportOnlyData="true" HideStructureColumns="true" IgnorePaging="false">
                            <Excel Format="ExcelML" />
                        </ExportSettings>
                        <MasterTableView AllowPaging="true" ShowHeadersWhenNoRecords="true"
                            CommandItemDisplay="Top" EditMode="InPlace" EnableColumnsViewState="false">
                            <Columns>
                                <telerik:GridEditCommandColumn HeaderStyle-Width="40" ButtonType="ImageButton" UniqueName="EditCommandColumn"
                                    EditText="Modifica">
                                    <ItemStyle HorizontalAlign="Center" />
                                </telerik:GridEditCommandColumn>
                                <telerik:GridButtonColumn ConfirmText="Eliminare questo record in maniera definitiva?"
                                    ConfirmDialogType="RadWindow" ConfirmTitle="Delete" ButtonType="ImageButton"
                                    CommandName="Delete" Text="Elimina" UniqueName="DeleteColumn">
                                    <ItemStyle HorizontalAlign="Center" Width="40" />
                                </telerik:GridButtonColumn>
                            </Columns>
                            <CommandItemSettings ShowExportToExcelButton="true" />
                        </MasterTableView>
                    </telerik:RadGrid>
                    <asp:HiddenField ID="txtCurrentTable" runat="server" />                    
                </telerik:RadAjaxPanel>

Regards!

Cristian

1 Answer, 1 is accepted

Sort by
0
Accepted
Tsvetina
Telerik team
answered on 31 Jan 2011, 08:26 AM
Hi Martini,

When you dynamically create the columns of a statically declared grid, you should do that in Page_Load since the ViewState is not yet available in Page_Init. See this help article and more specifically the example relevant to your scenario:

Dynamically defining the structure of a statically-declared grid

Additionally, RadGrid does not support having dynamically and statically created columns at the same time, so you would need to also create the button column and edit command column dynamically.

Best wishes,
Tsvetina
the Telerik team
Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.
Tags
Grid
Asked by
Lasly
Top achievements
Rank 1
Answers by
Tsvetina
Telerik team
Share this question
or