NewBie
NewBie

Reputation: 1844

Maximum request length exceeded exception on postback

I'm getting the following exception on a button click, for an asp page which binds more than 500 records in a gridview on page load.

My page does not have any upload control. It contains a textbox, button and the gridview. Does anyone know why this is happening.

Exception Description:

Maximum request length exceeded.
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. 

Upvotes: 11

Views: 18853

Answers (1)

bgs264
bgs264

Reputation: 4642

A postback sends back the viewstate of every control - if you have a huge datagrid, then when the browser reposts that to the server, this is why you are getting the exception.

Your two options are:

  1. Set EnableViewState="false" on your GridView if you do not need the viewstate, so it's not so bloated and the postback is a reasonable size,
  2. Increase the maximum request size in web.config as shown below:

    <configuration>
        <system.web>
            <httpRuntime maxRequestLength="32768" />
        </system.web>
    </configuration>
    

Hope this helps

Upvotes: 25

Related Questions