Click here to Skip to main content
12,698,179 members (22,616 online)
Rate this:
 
Please Sign up or sign in to vote.
I have got an error when i bind multiple records for input.

I bind Gridview inside Datalist to form a matrix like input which will update the value. my form is successfully running at localhost; but when i run it on my webserver it give me this error.

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() +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


i have set MaxHttpCollectionKeys value in webconfig file like this, but nothing happen.
<appSettings>
    <add key="aspnet:MaxHttpCollectionKeys" value="5001" />
</appSettings>


Please, give me solution for this query.
Posted 26-Sep-12 23:08pm
Updated 27-Sep-12 0:01am
v3
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

Hello,

We got same error during document uploading then apply following setting in web config file. please verify appSettings block properly added or not.

<appSettings>
      <add key="aspnet:MaxHttpCollectionKeys" value="2001" />
</appSettings>

and it work in our application .

Please refer below URL for reference.

reference URL:  http://stackoverflow.com/questions/8832470/operation-is-not-valid-due-to-the-current-state-of-the-object-error-during-pos


Please let us know if any.
  Permalink  
Comments
Mohd Imran Saifi 27-Sep-12 4:43am
   
Thanks for your answer. I think you don't read all the question. i had already do that but it can help. i already exceeded the value as i mentioned in my question, but nothing changes.
Member 2733050 27-Feb-13 2:23am
   
Hi...I too have the same problem. Have you solved the same as yet?
sivasaikrishna 28-Jun-13 3:03am
   
Hi I too have same problem i changed appsettings but not working
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 2

Previously,I use hiddenfields to save the additional values for database manipulation.
so,by this i got too many control on webpage.and it show me error which i described.
to get rid of this error i do these steps.
<appSettings>
    <add key="aspnet:MaxHttpCollectionKeys" value="5001" />
</appSettings>

and
I have updated the HiddenFields to Literals & everything is working as it should.
  Permalink  
Comments
ravikhoda 12-Sep-14 3:17am
   
is it ok if we apply paging on gridview which has hidden field in the item template?
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 3

Micosoft has given some fix for this, This solves your problem.
http://geekswithblogs.net/Vipin/archive/2012/03/05/throwifmaxhttpcollectionkeysexceeded-error-message-when-doing-postback.aspx[^]
It depends on your page POSTData so you keep on increase the value in the web.config>appSettings>aspnet:MaxHttpCollectionKeys-->value="10000". until it stops throwing that error.
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web01 | 2.8.170118.1 | Last Updated 14 Mar 2014
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100