Is there any limit to Hidden Field Length in ASP.net

Taha Rehman Siddiqui picture Taha Rehman Siddiqui · Mar 26, 2013 · Viewed 10.6k times · Source

I am experiencing a strange error (not very strange, i guess it is because of some maximum length restriction i might not know about). I am working on a Custom Server Control, which renders a Custom Search Service for employees. When the employees are searched successfully, I fetch their whole objects (List) from WCF service in json, keep the string in a hidden field, and postback for the code behind to fetch json string and deserialize into objects. Now, up to 2000 objects, it was working flawlessly, but when the search criteria started fetching above 2000, the following error started occuring

Uncaught Sys.WebForms.PageRequestManagerServerErrorException: Sys.WebForms.PageRequestManagerServerErrorException: An unknown error occurred while processing the request on the server. The status code returned from the server was: 0 

I debugged the code as well, but the c# code was not even catching any calls. I also tried keeping the json strings of objects in multiple hidden fields with each having 1000 records in json string. But still, the error keep coming up. This tells me there is some sort of restriction of maximum size to the form. Can i get any solution for this problem, or do I have to go with sending Ids to the code behind and fetching the Objects from the Service there? Actually, the service url is supposed to be dynamic, the host application would be providing it, so I am trying not to introduce any service binding on C# level(you get the idea, i guess).

Answer

Brian Rogers picture Brian Rogers · Mar 26, 2013

ASP.NET does have a maximum request size-- it is 4MB by default, according to the documentation. If you think you might be hitting that limit, you can increase it by adding the following to your web.config file inside the <system.web> tag:

<httpRuntime maxRequestLength="x">

where x is the desired maximum in Kilobytes. So for example, 10240 would be 10MB.