Whenever you request a page from a server it responds by sending the generated HTML of the page. Server also stores the form data into a hidden variable with name __VIEWSTATE. This information is needed by server to maintain state of the page across postbacks. On every request the server reads this variable and populates the control with values from previous request, then populates the postback data, fires the event again generates the ViewState and send it with HTML.
Thus the more the controls there are on the page, more will be the size of the Viewstate.
Since this needs a good amount of serialization and deserialization, as a matter of good design, you should always strive to include as little information in view state as possible, which ensures the better performance.
The size of the hidden view state field has no limit. However, some proxy servers and firewalls refuse to let pages through if they have hidden fields greater than a certain size. To avoid this problem view state chunking can be used, which automatically divides view state into multiple fields to ensure that no hidden field exceeds a size threshold you set. To use view state, you simply need to set the maxPageStateFieldLength attribute of the <pages> element in the web.config file. This specifies the maximum view state size, in bytes. Here’s an example this caps the view state at 2 KB:
<configuration> <system.web> <pages maxPageStateFieldLength = "2048" /> </system.web> </configuration>
When you request a page that generates a view state larger than this, several hidden input fields will be created:
. . . [/CODE[ View state chunking in no way improves performance. It rather puts some extra serialization efforts and thus should be used only when needed.
You can control the viewstate by setting EnableViewState property available with all ASP.Net server controls but there is an exception to it. Even if you set EnableViewState to false, the control can still hold onto a smaller amount of view state information that it deems critical for proper functioning. This privileged view state information is known as control state, and it can never be disabled. However, in a well-designed control the size required for control state will be significantly smaller than the size of the entire view state.
|
No responses found. Be the first to respond and make money from revenue sharing program.
|