【问题标题】:Operation is not valid due to the current state of the object in asp.net [duplicate]由于asp.net中对象的当前状态,操作无效[重复]
【发布时间】:2012-10-06 21:14:07
【问题描述】:

可能重复:
'Operation is not valid due to the current state of the object' error during postback

[InvalidOperationException: Operation is not valid due to the current state of the object.]
   System.Web.HttpValueCollection.ThrowIfMaxHttpCollectionKeysExceeded() +2420862
   System.Web.HttpValueCollection.FillFromEncodedBytes(Byte[] bytes, Encoding encoding) +58
   System.Web.HttpRequest.FillInFormCollection() +159

[HttpException (0x80004005): The URL-encoded form data is not valid.]
   System.Web.HttpRequest.FillInFormCollection() +217
   System.Web.HttpRequest.get_Form() +104
   System.Web.HttpRequest.get_HasForm() +9038959
   System.Web.UI.Page.GetCollectionBasedOnMethod(Boolean dontReturnNull) +97
   System.Web.UI.Page.DeterminePostBackMode() +69
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +135

一次又一次地得到这个错误

我的代码在后面!! 取消按钮位于 DATAGRID 内

if (((System.Web.UI.WebControls.Button)e.CommandSource).CommandName == "Cancel")
    {
        string value = (e.Item.FindControl("txtStatDesc") as System.Web.UI.WebControls.Label).Text;

        if (value.Equals("Sent", StringComparison.CurrentCultureIgnoreCase))
        {
            Page.ClientScript.RegisterStartupScript(this.GetType(), "Alert", "alert('You can not cancel the dta because it is in sent mode. Cancellation refused');", true);

        }


       else if (value.Equals("Prepared", StringComparison.CurrentCultureIgnoreCase))
            Page.ClientScript.RegisterStartupScript(this.GetType(), "Alert", "alert('DEF');", true);

       else
            Page.ClientScript.RegisterStartupScript(this.GetType(), "Alert", "alert('xyz');", true);



    }

【问题讨论】:

    标签: asp.net c#-4.0 error-handling runtime-error


    【解决方案1】:

    我猜是您的数据网格造成了麻烦,因为只有当您的表单中有超过 1000 个数据元素时才会发生该错误。 Microsoft 在 2011 年添加了该限制,以解决拒绝服务漏洞。

    有关限制以及如何在需要时提高限制的更多信息can be found here

    【讨论】:

    • 出现同样的错误仍然无法正常工作:/
    • @vini 你把它抬高了多少,你的网格有多大?
    • 现在可以工作了,谢谢把它提高到 20,000,但是把它提高到这么高有什么可能吗?
    • @vini 本身不是问题,它可以限制POST 所需的 CPU 数量。如果您的应用程序需要如此高的限制,从长远来看,您可能需要重新考虑发布大数据网格。
    猜你喜欢
    • 2012-05-22
    • 2022-10-13
    • 2010-10-18
    • 1970-01-01
    • 2020-04-30
    • 1970-01-01
    相关资源
    最近更新 更多