Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Maximum request length exceeded exception on postback

Tags:

.net

asp.net

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. 
like image 250
NewBie Avatar asked May 25 '12 09:05

NewBie


1 Answers

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

like image 54
bgs264 Avatar answered Oct 20 '22 00:10

bgs264