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

Error when using validator

2 Answers 48 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Chad Johnson
Top achievements
Rank 1
Chad Johnson asked on 22 Oct 2008, 08:17 PM
Greetings,

I have a grid that has only three entries in it with three columns, with 2 visible and the 3rd hidden.  One of my columns is a template that has a label in the Item Template, and a textbox and validator to validate the textbox in the Edit Template.  I have set the grid up to use validation, and I am only doing editing for this grid.  Here is the code for the grid.

<telerik:RadGrid ID="rgdStatusList" runat="server" AllowPaging="True" AllowSorting="True" 
        AutoGenerateColumns="False" DataSourceID="odsGetStatusList" GridLines="None" 
        OnNeedDataSource="rgdStatusList_NeedDataSource" ShowGroupPanel="false" 
        OnItemCommand="rgdStatusList_ItemCommand" ShowStatusBar="True"   
        AllowMultiRowSelection="true" PageSize="30" OnItemDataBound="rgdStatusList_ItemDataBound" 
        onprerender="rgdStatusList_PreRender" OnInsertCommand="rgdStatusList_InsertCommand" Width="275px" 
        OnPageIndexChanged="rgdStatusList_PageIndexChanged" OnDeleteCommand="rgdStatusList_DeleteCommand">  
        <ValidationSettings EnableValidation="true" /> 
        <MasterTableView DataKeyNames="StatusID" DataSourceID="odsGetStatusList" CommandItemDisplay="Top" 
        EditMode="InPlace">  
        <PagerStyle Mode="NextPrevNumericAndAdvanced" Position="TopAndBottom" /> 
            <CommandItemTemplate> 
                <telerik:RadToolBar ID="rtbToolBar" OnButtonClick="rtbToolBar_ButtonClick" runat="server" 
                    OnClientButtonClicking="onToolBarClientButtonClicking">  
                    <Items> 
                        <telerik:RadToolBarButton Text="Add Status" SkinID="AddBtn" CommandName="InitInsert" ToolTip="Add Status Code" 
                            Visible='<%# !rgdStatusList.MasterTableView.IsItemInserted %>'>  
                        </telerik:RadToolBarButton> 
                        <telerik:RadToolBarButton Text="Save Status" SkinID="AddBtn" CommandName="PerformInsert" ToolTip="Save Status" 
                            Visible='<%# rgdStatusList.MasterTableView.IsItemInserted %>' ValidationGroup="validate">  
                        </telerik:RadToolBarButton> 
                        <telerik:RadToolBarButton Text="Cancel" SkinID="CancelBtn" CommandName="CancelAll" ToolTip="Cancel" 
                            Visible='<%# rgdStatusList.MasterTableView.IsItemInserted %>'>  
                        </telerik:RadToolBarButton> 
                        <telerik:RadToolBarButton Text="Delete Status" SkinID="DeleteBtn" CommandName="DeleteSelected" ToolTip="Delete Status Code" 
                            Visible='<%# !rgdStatusList.MasterTableView.IsItemInserted %>'>  
                        </telerik:RadToolBarButton> 
                        <telerik:RadToolBarButton Text="Set Defaults" SkinID="SetDefaultsBtn" CommandName="SetDefaults" ToolTip="Set Defaults">  
                        </telerik:RadToolBarButton> 
                    </Items> 
                </telerik:RadToolBar> 
            </CommandItemTemplate> 
            <RowIndicatorColumn> 
            <HeaderStyle Width="20px"></HeaderStyle> 
            </RowIndicatorColumn> 
            <ExpandCollapseColumn> 
            <HeaderStyle Width="20px"></HeaderStyle> 
            </ExpandCollapseColumn> 
            <Columns> 
                <telerik:GridBoundColumn DataField="StatusID" DataType="System.Int32"   
                    HeaderText="Status ID" SortExpression="StatusID" UniqueName="StatusID" ReadOnly="true" 
                    Visible="false">  
                </telerik:GridBoundColumn> 
                <telerik:GridTemplateColumn DataField="StatusDescription" HeaderText="Status Name" 
                    SortExpression="StatusDescription" UniqueName="StatusDescription" EditFormColumnIndex="1">  
                    <ItemTemplate> 
                        <asp:Label ID="lblStatusDesc" runat="server" 
                            Text='<%# DataBinder.Eval(Container, "DataItem.StatusDescription")%>'>  
                        </asp:Label> 
                    </ItemTemplate> 
                    <EditItemTemplate> 
                        <telerik:RadTextBox ID="txtStatusDesc" runat="server" Text="" Width="200" MaxLength="26">  
                        </telerik:RadTextBox> 
                        <br /> 
                        <asp:RequiredFieldValidator ID="rfvStatusDesc" runat="server" ControlToValidate="txtStatusDesc" 
                            ErrorMessage="You cannot have a blank Status Description." SetFocusOnError="true" 
                            ValidationGroup="validate" Display="Dynamic">  
                        </asp:RequiredFieldValidator> 
                    </EditItemTemplate> 
                </telerik:GridTemplateColumn> 
                <telerik:GridTemplateColumn UniqueName="Active" DataField="Active" SortExpression="Active" 
                    HeaderText="Type" EditFormColumnIndex="1">  
                <ItemTemplate> 
                    <asp:Label ID="lblStatusType" runat="server" Text='<%# TypeStatus(DataBinder.Eval(Container, "DataItem.Active"))%>'>  
                    </asp:Label> 
                </ItemTemplate> 
                <EditItemTemplate> 
                    <asp:CheckBox ID="chkActive" runat="server" ToolTip="Click to set this Status to an Active Type" /> 
                </EditItemTemplate> 
                </telerik:GridTemplateColumn> 
            </Columns> 
            <EditFormSettings ColumnNumber="2">                  
            </EditFormSettings> 
        </MasterTableView> 
        <ClientSettings> 
            <Selecting AllowRowSelect="true" /> 
        </ClientSettings> 
        <FilterMenu EnableTheming="True">  
        <CollapseAnimation Type="OutQuint" Duration="200"></CollapseAnimation> 
        </FilterMenu> 
        <StatusBarSettings ReadyText="Ready" /> 
        <ValidationSettings CommandsToValidate="PerformInsert" /> 
    </telerik:RadGrid> 

Anyways, when I start editing, the validator functions properly.  Then when I try to save what is in the textbox when something is in it, I get this error:

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.

There are no controls being added or taken off, and for the life of me, I can't figure out what it's talking about.  If someone could help me, I'd be very appreciative.  Thanks.

~ Chad

2 Answers, 1 is accepted

Sort by
0
Nikolay Rusev
Telerik team
answered on 27 Oct 2008, 04:58 PM
Hello Chad,

Unfortunately I am not able to determine what might cause the issue which you are currently facing.
I suspect the reason for the unwanted behavior is in the way you handle RadGrid events.

I suggest you open a formal support ticket and send us a subset of your project that replicates the issue. Thus we'll be able to help you further on this.

Best regards,
Nikolay
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Chad Johnson
Top achievements
Rank 1
answered on 27 Oct 2008, 06:09 PM
I thank you for your answer, but I was able to finally figure out what the problem was.  The problem was in my code behind, where my grid rebound itself after someone clicked a button in the toolbar, which was my own fault.  Again, I thank you for your time to answer.

~ Chad
Tags
Grid
Asked by
Chad Johnson
Top achievements
Rank 1
Answers by
Nikolay Rusev
Telerik team
Chad Johnson
Top achievements
Rank 1
Share this question
or