0

Possible Duplicate:
'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

Getting this error again and again

My code behind!! The cancel button is inside a 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);



    }
Community
  • 1
  • 1
vini
  • 4,657
  • 24
  • 82
  • 170

1 Answers1

2

I'm guessing it's your datagrid causing trouble, since that error will only happen if you have more than 1000 data elements in your form. The restriction was added in 2011 by Microsoft to address a denial of service exploit.

More information on the restriction and how to raise the limit if needed can be found here.

Joachim Isaksson
  • 176,943
  • 25
  • 281
  • 294