对象的当前状态使该操作无效。 
说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。 异常详细信息: System.InvalidOperationException: 对象的当前状态使该操作无效。源错误: 执行当前 Web 请求期间生成了未处理的异常。可以使用下面的异常堆栈跟踪信息确定有关异常原因和发生位置的信息。 
堆栈跟踪: 
[InvalidOperationException: 对象的当前状态使该操作无效。]
   System.Web.HttpValueCollection.ThrowIfMaxHttpCollectionKeysExceeded() +2692482
   System.Web.HttpValueCollection.FillFromEncodedBytes(Byte[] bytes, Encoding encoding) +61
   System.Web.HttpRequest.FillInFormCollection() +148[HttpException (0x80004005): URL 编码窗体数据无效。]
   System.Web.HttpRequest.FillInFormCollection() +206
   System.Web.HttpRequest.get_Form() +68
   System.Web.HttpRequest.get_HasForm() +8743911
   System.Web.UI.Page.GetCollectionBasedOnMethod(Boolean dontReturnNull) +97
   System.Web.UI.Page.DeterminePostBackMode() +63
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +133

解决方案 »

  1.   

    URL 编码窗体数据无效
    代码的问题啊
      

  2.   

    <asp:GridView ID="GvListInfo" runat="server" SkinID="gridviewSkin" 
    Width="95%" AutoGenerateColumns="False"
    OnRowCancelingEdit="GvListInfo_RowCancelingEdit" DataKeyNames="PK_EmpSalesDetail,PK_Dealer,PersonType"
    OnRowEditing="GvListInfo_RowEditing"  OnRowUpdating="GvListInfo_RowUpdating" 
    onrowdatabound="GvListInfo_RowDataBound" AllowPaging="True" 
     PageSize="1000" onpageindexchanging="GvListInfo_PageIndexChanging" 
     onrowdeleting="GvListInfo_RowDeleting">
     <RowStyle HorizontalAlign="Center" />
          <Columns>
              <asp:TemplateField>
                  <ItemTemplate>
                  <asp:CheckBox ID="CheckBox1" runat="server" />
                   </ItemTemplate>
                <HeaderTemplate>
             <asp:CheckBox ID="CbAllCheck" runat="server" Text="全选" AutoPostBack="True" OnCheckedChanged="CbAllCheck_CheckedChanged" />
            </HeaderTemplate>
      </asp:TemplateField>
    </Columns>
       </asp:GridView>
      protected void CbAllCheck_CheckedChanged(object sender, EventArgs e)
        {
            CheckBox cbAll = (CheckBox)sender as CheckBox;
              foreach (GridViewRow row in GvListInfo.Rows)
                {
                    CheckBox cb = (CheckBox)row.Cells[0].FindControl("CheckBox1");
                    cb.Checked = cbAll.Checked  ;
             }
       }当数据量大时 点击gridview中的全选按钮 就会抛异常
      

  3.   

     <script type="text/javascript">
               function selectAll() {
                   // 获得用户页面中的所有的 输入功能的控件getElementById("ChkSelect").
                   var checkbox = document.getElementsByTagName("input");
                   if (checkbox[0].checked == true) {
                       for (var i = 0; i < checkbox.length; i++)
                           checkbox[i].checked = false;
                   }
                   else {
                       for (var i = 0; i < checkbox.length; i++)
                           checkbox[i].checked = true;
                   }
               }    </script>
      

  4.   


    应该不是 checkbox的问题,点击按钮  获取被选中 栏位的信息时也报同样的异常
      

  5.   

    微软发布安全补丁 修复.NET Framework漏洞
    http://www.dnjsb.com/zhishi/IT/2011/1231/5281.html跟这个补丁有关。
      

  6.   

    若是net framework 1.1 ,下载其对应的MS11-100安装包,然后修改注册表即可。
      

  7.   

    PageSize="1000"数据量有点儿大,估计页面受不了,不能设小点儿吗
      

  8.   

    PageSize 大小应该无关, 页面加载后 触发服务器控件 会抛出异常,而不是加载时就抛异常
      

  9.   

    也会 引发:[HttpUnhandledException]: 引发类型为“System.Web.HttpUnhandledException”的异常。
      

  10.   

    若不是1.1,在web.config添加如下配置:
    <appSettings>
      <add key="aspnet:MaxHttpCollectionKeys" value="1001" />
    </appSettings>* 若无效,下载安装补丁包
    http://technet.microsoft.com/en-us/security/bulletin/ms11-100
      

  11.   

    其中,MaxHttpCollectionKeys对应value值你可根据画面的待提交的控件最大数量来设置
      

  12.   

    MaxHttpCollectionKeys对应value值 如果设置过大会不会有什么影响
      

  13.   

    试了下 点击 Checkbox 是可行的 但可能是页面承载的数据量太大   重复点几次 就又会抛出异常
    [InvalidOperationException: 对象的当前状态使该操作无效。]
    [HttpException (0x80004005): URL 编码窗体数据无效。]
    [HttpUnhandledException]: 引发类型为“System.Web.HttpUnhandledException”的异常。
    在 System.Web.UI.Page.HandleError(Exception e)
       在 System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
       在 System.Web.UI.Page.ProcessRequest(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
       在 System.Web.UI.Page.ProcessRequest()
       在 System.Web.UI.Page.ProcessRequestWithNoAssert(HttpContext context)
       在 System.Web.UI.Page.ProcessRequest(HttpContext context)
       在 ASP.content_3csalesweb_employeesaleslistseach_aspx.ProcessRequest(HttpContext context) 位置 c:\Users\aaen\AppData\Local\Temp\Temporary ASP.NET Files\cweb\48229cbb\2dbb4478\App_Web_mfh1pmfe.6.cs:行号 0
       在 System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
       在 System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)
     
      

  14.   

    我找到解决方案了:
    ThrowIfMaxHttpCollectionKeysExceeded()
    问题在这里.
    出现这个异常的原因正是因为上年12月29号那次微软发布的最后一次非正常更新程序引起的.在这次安全更新中对于asp.net单次的提交量做了一个最大量限制1000,出现这个异常正是因为页面提交量超过了1000这个限制.这个可以在web.config中更改:
    <appSettings>
    <add key="aspnet:MaxHttpCollectionKeys" value="5000" />
    </appSettings>
    这个也是我在一个国外网站上找到的.在我的项目中已经得到解决.给分吧,呵呵
      

  15.   

    随贴上原文网址:
    http://www.dotnetspider.com/forum/302424-Operation-not-valid-due-current-state-object.aspx
      

  16.   

    同样遇到这样的状况,据国外相关人士讲解,是微软于2011年12月29日更新的一个补丁造成的。痛苦啊<appSettings>
    <add key="aspnet:MaxHttpCollectionKeys" value="10000" />
    </appSettings>
    对我的程序依然无效