Thursday 29 December 2011

How To Apply "ViewStateMode for individual control"


WHAT IS VIEWSTATE: 
View State property of ASP.NET provides the functionality of “automatically storing values between multiple requests” for the same page. It is a client side state management mechanism that can store the page value at the time of sending and receiving information from server.
Ex-Like EmailID, Username in various sites.

LIMITATION IN PREVIOUS VERSION:
In previous version of ASP.NET developer could not enable view state for individual controls. This functionality is available only at the page level.

Only the thing was available in previous version, developers could disable view state for individual controls in order to reduce page size, but had to do so explicitly for individual controls.

IMPROVEMENTS IN ASP.NET 4.0:                         
In ASP.NET 4.0, a ViewStateMode property is included that allows developer to disable viViewState at the page level and then enable it only for the controls that require it in the page. ViewStateMode has 3 values:
  • Enabled enables the view state for this control and any child control.
  • Disabled disable the view state.
  • Inherits this specify the control uses the settings from its parent control.
 WHY MAKE CHANGES:
In earlier versions of ASP.NET by default this ViewState property is enabled at page level, so each control on the page potentially stores view state even if it is not required for the application. This increases the page size and the performance for our application is decreases.

To overcome this problem developer had to disable ViewState for individual control explicitly and it was very irritating for big applications.

HOW TO APPLY VIEW STATE MODE FOR INDIVIDUAL CONTROL:
For applying ViewState mode for individual control you have to follow these steps:
  • Disable ViewState at the page level in your application as shown in picture-
 


  •  Then write ViewStateMode=”Enabled” for the controls that require in the page as shown in the picture-

Now ViewState mode is enabled for the individual control that require in the page. This will reduce the page size aur now your application becomes more responsive.

BENEFITS:

          This feature permits developer to enable viewstate for individual controls which are required in the page.
          As  a result the size of the pages is reduced and your application becomes more responsive.
          By applying this feature in your application, a significant performance improvement can be gained in response-time.
          A good use for this feature is with ContentPlaceHolder controls in master pages, where ViewStateMode can be set to Disabled for the master page and then enable it individually for ContentPlaceHolder controls that in turn contain controls that require view state.



1 comment: