Click here to Skip to main content
15,891,372 members
Please Sign up or sign in to vote.
5.00/5 (1 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.
XML
<appSettings>
    <add key="aspnet:MaxHttpCollectionKeys" value="5001" />
</appSettings>


Please, give me solution for this query.
Posted
Updated 26-Sep-12 23:01pm
v3
Comments
Member 13122200 3-May-23 5:57am    
Operation is not valid due to the current state of the object. Why is this message hiding the designer tab in Visual Studio 2022 Preview C#?

Hello,

XML
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.
 
Share this answer
 
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?
ShivSai 28-Jun-13 3:03am    
Hi I too have same problem i changed appsettings but not working
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.
XML
<appSettings>
    <add key="aspnet:MaxHttpCollectionKeys" value="5001" />
</appSettings>

and
I have updated the HiddenFields to Literals & everything is working as it should.
 
Share this answer
 
Comments
ravikhoda 12-Sep-14 3:17am    
is it ok if we apply paging on gridview which has hidden field in the item template?
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.
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900