8.27.2012

EnableViewState vs ViewStateMode

Difference between EnableViewState and ViewStateMode properties

S.No EnableViewState ViewStateMode
1
Property Introduction:
EnableViewState exists from a long time
Property Introduction:
ViewStateMode property is introduced in ASP.NET 4
2
Available Values:
EnableViewState property only accepts true or false values
Available Values:
ViewStateMode property can have a value of - Enabled, Disabled and inherit.
3
Default Value:
True
Default Value:
Inherit
4
What EnableViewState does ?
To enable ViewState at Page level
What ViewStateMode does ?
To enable ViewState at Control level
5
How to use ?
Using EnableViewState property we can have one of these 2 options.

i. We can turn off view state altogether by setting its value to false in web.config file,or
ii.Enable viewstate for the entire page and then turn it off on a control-by-control basis.
How to use ?
Steps involved to disable view state for a page and to enable it for a specific control on the page,

i. Set the EnableViewState property of the page and the control to true,
ii. Set the ViewStateMode property of the page to Disabled, and
iii. Set the ViewStateMode property of the control to Enabled.

Summary:

1. If EnableViewState is to True, only then the ViewStateMode settings are applied.
2. In other words, if EnableViewState is set to False, ViewStateMode setting is not respected
3. Therefore, we have to use ViewStateMode property in conjunction with EnableViewState.

1 comment:

  1. "Nice and good article.. it is very useful for me to learn and understand easily.. thanks for sharing your valuable information and time.. please keep updating.php jobs in hyderabad.
    "

    ReplyDelete