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

Operation is not valid due to the current state of the object.

1 Answer 549 Views
Button
This is a migrated thread and some comments may be shown as answers.
Cecil
Top achievements
Rank 1
Cecil asked on 23 Jan 2012, 01:13 AM
I started with a simple grid on a page as follows:
<telerik:RadGrid ID="rgSelectCourses" runat="server" AllowSorting="True"
     Width="860px" Height="500px" PageSize="20" CellSpacing="0"
     DataSourceID="sdsCourses" AllowMultiRowSelection="True"
     GridLines="None" AutoGenerateColumns="False">
     <ClientSettings>
         <Scrolling AllowScroll="True" UseStaticHeaders="True" />
         <Selecting AllowRowSelect="true" />
     </ClientSettings>
     <MasterTableView DataKeyNames="Course_Code" DataSourceID="sdsCourses">
         <CommandItemSettings ExportToPdfText="Export to PDF" />
         <RowIndicatorColumn FilterControlAltText="Filter RowIndicator column"
             Visible="True">
         </RowIndicatorColumn>
         <ExpandCollapseColumn FilterControlAltText="Filter ExpandColumn column"
             Visible="True">
         </ExpandCollapseColumn>
         <Columns>
             <telerik:GridClientSelectColumn Reorderable="False" UniqueName="ClientSelectColumn" HeaderText="Select">
             <HeaderStyle Width="50px"></HeaderStyle>
             </telerik:GridClientSelectColumn>
         <telerik:GridBoundColumn UniqueName="Course_Code" SortExpression="Course_Code" HeaderText="Code"
             DataField="Course_Code">
             <HeaderStyle Width="130px"></HeaderStyle>
             <ItemStyle HorizontalAlign="Left" />
         </telerik:GridBoundColumn>
          <telerik:GridBoundColumn UniqueName="Course_Title" SortExpression="Course_Title" HeaderText="Title"
             DataField="Course_Title">
             <HeaderStyle Width="200px"></HeaderStyle>
             <ItemStyle HorizontalAlign="Left" />
         </telerik:GridBoundColumn>
         <telerik:GridTemplateColumn FilterControlAltText="Filter column1 column" HeaderText="Expiration Date" UniqueName="column1">
             <HeaderStyle HorizontalAlign="Center" />
             <ItemStyle Width="120px" HorizontalAlign="Center" />
             <ItemTemplate>
                 <telerik:RadComboBox ID="rgTime" runat="server" Width="35px">
                     <Items>
                         <telerik:RadComboBoxItem runat="server" Text="1" Value="1" />
                         <telerik:RadComboBoxItem runat="server" Text="2" Value="2" />
                         <telerik:RadComboBoxItem runat="server" Text="3" Value="3" />
                         <telerik:RadComboBoxItem runat="server" Text="4" Value="4" />
                         <telerik:RadComboBoxItem runat="server" Text="5" Value="5" />
                         <telerik:RadComboBoxItem runat="server" Text="6" Value="6" />
                         <telerik:RadComboBoxItem runat="server" Text="7" Value="7" />
                         <telerik:RadComboBoxItem runat="server" Text="8" Value="8" />
                         <telerik:RadComboBoxItem runat="server" Text="9" Value="9" />
                         <telerik:RadComboBoxItem runat="server" Text="10" Value="10" />
                         <telerik:RadComboBoxItem runat="server" Text="11" Value="11" />
                         <telerik:RadComboBoxItem runat="server" Text="12" Value="12" />
                     </Items>
                 </telerik:RadComboBox>
                   
                 <telerik:RadComboBox ID="rgInterval" runat="server" Width="60px">
                     <Items>
                         <telerik:RadComboBoxItem runat="server" Text="Years" Value="Years" />
                         <telerik:RadComboBoxItem runat="server" Text="Months" Value="Months" />
                     </Items>                         
                 </telerik:RadComboBox>                           
             </ItemTemplate>
         </telerik:GridTemplateColumn>
         <telerik:GridTemplateColumn FilterControlAltText="Filter column2 column"
             HeaderText="Comments..." UniqueName="column2">
             <HeaderStyle Width="300px" HorizontalAlign="Left" />
             <ItemStyle HorizontalAlign="Left" />
             <ItemTemplate>
                 <telerik:RadTextBox ID="rtbComment" runat="server" TextMode="Multiline"
                     Height="63px" Width="290px" />
             </ItemTemplate>
         </telerik:GridTemplateColumn
         </Columns>
         <EditFormSettings>
             <EditColumn FilterControlAltText="Filter EditCommandColumn column">
             </EditColumn>
         </EditFormSettings>
     </MasterTableView>
     <FilterMenu EnableImageSprites="False">
     </FilterMenu>
     <HeaderContextMenu CssClass="GridContextMenu GridContextMenu_Default">
     </HeaderContextMenu>
 </telerik:RadGrid>
 
 <asp:SqlDataSource ID="sdsCourses" runat="server"
     ConnectionString="<%$ ConnectionStrings:SafetyPlusWebConnectionString %>"
     SelectCommand="SELECT [Course_Code], [Course_Title], [Renewal_Interval], [Time_Frame] FROM [Courses] WHERE [Active] = 1 ORDER BY [Course_Code]">
 </asp:SqlDataSource>

Everything worked perfectly.  I could select and edit items at will.

But, I needed to get the selected items into a database.  I chose to put a radbutton below the grid for the user to click when they had made all their changes.

<telerik:RadButton ID="RadButton1" runat="server" Text="Next" OnClick="RadButton1_Click" ></telerik:RadButton>

When the button is clicked, I get the following:
Operation is not valid due to the current state of the object.
 
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
 
Exception Details: System.InvalidOperationException: Operation is not valid due to the current state of the object.
 
Source Error:
 
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.
 
Stack Trace:
 
[InvalidOperationException: Operation is not valid due to the current state of the object.]
   System.Web.HttpValueCollection.ThrowIfMaxHttpCollectionKeysExceeded() +83
   System.Web.HttpValueCollection.FillFromEncodedBytes(Byte[] bytes, Encoding encoding) +111
   System.Web.HttpRequest.FillInFormCollection() +307
 
[HttpException (0x80004005): The URL-encoded form data is not valid.]
   System.Web.HttpRequest.FillInFormCollection() +404
   System.Web.HttpRequest.get_Form() +85
   System.Web.HttpRequest.get_Item(String key) +94
   Telerik.Web.UI.RadCompression.IsAjaxRequest() +59
   Telerik.Web.UI.RadCompression.Compress(HttpApplication application) +770
   Telerik.Web.UI.RadCompression.PreRequestHandlerExecute(Object sender, EventArgs e) +76
   System.Web.SyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +221
   System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +120
 
 
Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.272

Any thoughts on how to correct this?

Thx

1 Answer, 1 is accepted

Sort by
0
Richard
Top achievements
Rank 1
answered on 24 Jan 2012, 03:43 PM
Cecil:

I'm not sure if this is applicable to your situation, since I'm not privy to the details of your database update, but this recent post (1/18/2012) is worth reviewing, if you've not yet done so:

MS Update MS11-100 breaks sites with more than 1000 parameters at http://world.episerver.com/Blogs/Per-Nilsson/Dates/2012/1/MS-Update-MS11-100-breaks-sites-with-more-than-1000-parameters/

Hope this helps!
Tags
Button
Asked by
Cecil
Top achievements
Rank 1
Answers by
Richard
Top achievements
Rank 1
Share this question
or