ViewState Chunking (maxPageStateFieldLength)



When the ViewState in your page becomes very large it can be a problem since some firewalls and proxies will prevent access to pages containing huge ViewState sizes. For this purpose ASP.NET introduces the ViewState Chunking mechanism. So ASP.NET enables splitting of the ViewState's single hidden field into several using the MaxPageStateFieldLength property in the web.config <pages> section. This indicates the maximum bytes size allowed for one viewstate hidden field. If the real size exceeds the value then viewstate is split into multiple fields. By default, the attribute is set to -1 which means that no maximum size is defined.

When the MaxPageStateFieldLength property is set to a positive number, 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.

Setting the MaxPageStateFieldLength property to a negative number (the default) indicates that the view-state field should not be separated into chunks. Setting the MaxPageStateFieldLength to a small number may result in poor performance.

Sample ViewState before:

<input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE"
value="/wEPDwUKLTk2Njk3OTQxNg9kFgICAw9kFgICCQ88KwANAGQYAQUJR3Jp
ZFZpZXcxD2dk4sjERFfnDXV/hMFGAL10HQUnZbk="
/>

Then set in web.config:

<pages maxPageStateFieldLength=
"40">

Sample ViewState After :

<input type="hidden" name="__VIEWSTATEFIELDCOUNT" id="__VIEWSTATEFIELDCOUNT"
value="3" />
<input type="hidden" name="__VIEWSTATE"
id="__VIEWSTATE" value="/wEPDwUKLTk2Njk3OTQxNg9kFgICAw9kFgICCQ88" />
<input type="hidden" name="__VIEWSTATE1"
id="__VIEWSTATE1" value="KwANAGQYAQUJR3JpZFZpZXcxD2dk4sjERFfnDXV/" />
<input type="hidden" name="__VIEWSTATE2"
id="__VIEWSTATE2" value="hMFGAL10HQUnZbk="
/>

Shinu

erver'>

Similar Articles