Invalid viewstate error in page

The webpage is a simple registration type page. Each user has to fill around 200 fields. There is 1 parent table and 6 child tables. Each table info is displayed in separate AJAX tab panel and details gets saved on each tab navigation. I have hosted the website in intranet and concurrently the details were entered by 100 users. Initially everything went on well and entries were getting saved in the database but after sometime the AJAX loading image was displayed and the website appeared to be very slow. Details of users did not get saved in database. Finally Firefox browser crashed for some people and for some the application did not even get logged out also. The website hanged! I reset IIS also and everything went on for few minutes and the same problem started again! I have used NHibernate framework, AJAX, ASP.Net 4.0 as front end and SQL server 2008 as back end.

The following are the error details in the log file:

    2014-08-11 10:05:40,953 [22] INFO ASP.global_asax servername :  - 
************************* 11/08/2014 10:05 **************************** IP Address: Exception Type: System.Web.HttpException Exception: Request timed out. Source: 

    2014-08-11 10:05:40,984 [39] INFO ASP.global_asax servername :  - 
    ************************* 11/08/2014 10:05 ****************************`
    IP Address:
    Exception Type: System.Web.HttpException
    Exception: The client disconnected.
    Source: System.Web
    Stack Trace: 
       at System.Web.UI.ViewStateException.ThrowError(Exception inner, String persistedState, String errorPageMessage, Boolean macValidationError)
       at System.Web.UI.ViewStateException.ThrowViewStateError(Exception inner, String persistedState)
       at System.Web.UI.ClientScriptManager.EnsureEventValidationFieldLoaded()
       at System.Web.UI.ClientScriptManager.ValidateEvent(String uniqueId, String argument)
       at System.Web.UI.Control.ValidateEvent(String uniqueID, String eventArgument)
       at System.Web.UI.WebControls.DropDownList.LoadPostData(String postDataKey, NameValueCollection postCollection)
       at System.Web.UI.WebControls.DropDownList.System.Web.UI.IPostBackDataHandler.LoadPostData(String postDataKey, NameValueCollection postCollection)
       at System.Web.UI.Page.ProcessPostData(NameValueCollection postData, Boolean fBeforeLoad)
       at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
       at System.Web.UI.Page.ProcessRequest(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
       at System.Web.UI.Page.ProcessRequest()
       at System.Web.UI.Page.ProcessRequestWithNoAssert(HttpContext context)
       at System.Web.UI.Page.ProcessRequest(HttpContext context)
       at ASP.ui_shape_profilereg_aspx.ProcessRequest(HttpContext context)
       at System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
       at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)


    Inner Exception Type: System.Web.UI.ViewStateException
    Inner Exception: Invalid viewstate. 
        Client IP: xx.x.xx.xx
        Port: 44853
        Referer: mypageurl.aspx
        Path: /xx/xxxx/xxxxx.aspx
        User-Agent: Mozilla/5.0 (X11; Linux i686; rv:17.0) Gecko/20100101 Firefox/17.0
        ViewState: /wEW4xwCvIuN0AIC1tvizQkCq67tpAgC76DRtAcCx+CW8AkCub6h1gwCgL6h1gwC2tGLOAKy2oaCCQLvkqjEDgKhnYMvArnixL8OApuuotUNAvL6+LQMAr6MpOoPArqKsKgDAvHcqZUKAqz10osPAu71uZENAqOa+OUDAtH844kHApLejoMIApLe0pAOAqze2pAOAqze0pAOAqu34bMNAtGFvd4JAq3e2pAOAq3e0pAOAtKFvd4JAqu3pa0NAtGF4dsJAsyRw5MHAsyRu9kFAqu35bMNAtGFod4JAsyRx5MHAsyRv9kFAof0kuQOApj0kuQOAoibuIoCAo/tyqYKAvnF+KIIAunaxagHAuu0gK8OAr+m5s0MAp3r6bkJAp/A0coMAs+s/tsNAseN/JQOApaT7OIDAr/1vroLArWhqYQMAqDH34kLArCo9ecHAsuo0fkHAtCo0fkHAqa0zecNApe1zIMOAofa5u0CApja5u0CApna5u0CApra5u0CApva5u0CApza5u0CAp3a5u0CAp7a5u0CApbxu6IGAoaekcwKApmekcwKApiekcwKApuekcwKApqekcwKAp2ekcwKApyekcwKAp+ekcwKAo6ekcwKAoGekcwKApme0c8KApme3c8KApme2c8KApme5c8KApme4c8KApme7c8KApme6c8KApme9c8KApmescwKApmevcwKApie0c8KApie3c8KApie2c8KApie5c8KApie4c8KApie7c8KApie6c8KApie9c8KApie...
    Inner Source: 

    `2014-08-11 10:05:54,875 [82] INFO ASP.global_asax servername :  - 
    ************************* 11/08/2014 10:05 ****************************
    IP Address:
    Exception Type: System.Web.HttpException
    Exception: Request timed out.


These errors are repeatedly found in logs.

I have tried increasing the database size but have not tested after that.

I am completely stuck! Please guide how to proceed.


The following are the solutions I tried:

  • Generating specific machine key and aAdding enableViewstateMac="False" as specified in this article. Another useful article is presented in this link

  • When number of controls inside the page is large (we have around 200 controls), maxpagestatefieldlength property should be set to a smaller value, this field indicates that the view state sent to the client browser is broken into multiple hidden fields, and each field's value is less than the size specified in the MaxPageStateFieldLength property. We have specified maxpagestatefieldlength ="40"

  • We have done view state compression as specified in this article. The code compresses the viewstate and thus makes the website work fine in slow speed internet connections also!

  • The following are the tags we added in web.config file enableEventValidation="false" viewStateEncryptionMode="Never" enableViewStateMac="false". Please note that enableViewStateMac is set to true for security reasons. The MAC guarantees that the client cannot maliciously tamper with the contents of ViewState. (Encryption by itself isn't sufficient to guarantee this; the MAC is necessary.) The EnableViewStateMac property will be removed in a future version of the product since there is no valid reason to set it to 'false'.

  • Another one important mistake which we have done in the code is that we have used application variable to store error details in log and display it in error page also. Because of the use of application variable, when error occurs in one client, the application hangs up for remaining clients. We have removed that application variable and used a different approach for error handling.The error handling method which we have used was obtained from this article

  • We faced one issue during testing. The error is "Maximum request length exceeded" which was fixed by implementing the suggestions given in this article

  • We have used an update panel in our website, AJAX tab container was added inside it. Now we have removed that update panel and placed a separate update panel inside each tab panel.

  • The main reason for "Invalid Viewstate" error is the exception is thrown when the ViewState has become "large" and the user clicks a button before a previous request has completed... In our case this happens very easily because the post back is using ajax, so the browser doesn't stop responding while the ViewState is being sent to the server. Clicking on this control causes the exception over and over again. This concept is expained in this article but didn't get a proper workable solution in that link!

We have tested the website with 50 concurrent users and did not get any error! Hope this helps for all people facing this error!