Hi All

I have googled this exception extensively, and all the discussions I've found seem to be related to file uploading and exceeding the allowed file size limit. In my case however, I am not uploading anything, it is a simple postback.

I have a gridview displaying the results of an SQL query. This works correctly and displays the data as expected. Also, on the page are a couple dropdowns used to filter the data via control parameters on the SQL data source. However, any postback created on the page cause the above exception.

I have tested the query and all the filter parameters work as expected. I have tested removing various controls and cannot determine a single cause or point of failure, as the error occurs regardless of how the postback is triggered.

Any suggestions appreciated.

Recommended Answers

All 3 Replies

Whenever you post/submit the form, huge amount of data from client to server are sent and it exceed the 4 KB range(Default size of MaxRequestLength is 4 KB).

One possible cause would be improper use of "ViewState". May be you can turn off ViewState for GridView if you dont want to preseve the selection or something like that.

Secondly, your data-binding code (To populate dropdown) on page_load should be executed atmost once. You can use IsPostBack boolean property in page_load event:

public void Page_Load()
{
   if(!IsPostBack)
    {
     //populate DropDownLists
     }
} 

Thanks, disabling the viewstate for the grid solved the problem. I didn't realise the grid was posting the entirity of itself back each time (and since viewstate is ON by default).

Interestingly I wouldn't even get an exception in debug mode, the browser just got a connection reset.

I don't really see how your comment about the databinding occurrences relates to this, unless theres something I'm missing? I have the datasources set up in this case to bind automatically in the aspx page - ie: I'm not calling databind manually at all in code behind, so asp.net takes care of knowing when the controls need to be refreshed.

You don't need to disable viewstate, you can bump up the allowable size in the web.config:

<System.Web>
    <httpRuntime maxRequestLength="10000" />
</System.Web>

Another thing to watch out for is HttpValueCollection Key size. This is how many data elements are allowed on a page. Out of the box its around 1000, which is a decrease from framwwork 1.0. MS decreased it to prevent DoS attacks. On large gridviews this is easily exceeded, so to increase the number of keys allowable add this to the web.config:

<appsettings>
   <add key="aspnet:MaxHttpCollectionKeys" value="2000"></add>
</appsettings> 
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.