ViewStateMode vs EnableViewState

前端 未结 5 370
盖世英雄少女心
盖世英雄少女心 2020-12-29 18:34

What\'s the difference between:

  • ViewStateMode: Disabled / Enabled / Inherit
  • EnableViewState: True / False

It\'s in the properties of as

相关标签:
5条回答
  • 2020-12-29 18:50

    Here is a very useful article with a simple detailed example ASP.Net View State: EnableViewState vs ViewStateMode. The gist of it is:

    ViewStateMode property allows you to Disable View State at parent level and Enable it selectively at child level.

    EnableViewState property does not allow this.

    Both of these properties allow you to Enable view state at parent level and Disable it at child level.

    0 讨论(0)
  • 2020-12-29 18:53

    The combination allows you to turn off the ViewState for a page as a whole, but enable it for a specific control contained inside.

    To disable view state for a page and to enable it for a specific control on the page, set the EnableViewState property of the page and the control to true, set the ViewStateMode property of the page to Disabled, and set the ViewStateMode property of the control to Enabled.

    The default value of the ViewStateMode property for a page is Enabled. The default value of the ViewStateMode property for a Web server control in a page is Inherit. As a result, if you do not set this property at either the page or the control level, the value of the EnableViewState property determines view-state behavior.

    From Control.ViewStateMode Property

    0 讨论(0)
  • 2020-12-29 19:00

    EDIT

    ViewStateMode

    • Enabled - Turns the ViewState On for this control
    • Disabled - Turns the ViewState Off for this control
    • Inherit - Inherits from the value of the parent control

    EnableViewState

    • Overrides ViewStateMode, must be true for ViewStateMode to have meaning.

    See: Minimizing viewstate- confused by `EnableViewState` and `ViewStateMode` in asp.net 4.0

    ORIGINAL

    Understanding ASP.NET View State

    Gets or sets a value indicating whether the server control persists its view state, and the view state of any child controls it contains, to the requesting client. Control.EnableViewState Property

    You can use the ViewStateMode property to enable view state for an individual control even if view state is disabled for the page. For more information about view state and control state, see the EnableViewState property. Control.ViewStateMode Property

    0 讨论(0)
  • 2020-12-29 19:05

    ViewStateMode is used to change the result behavior of setting the EnableViewState of a page or a control to true.

    Refering to Control.ViewStateMode Property

    The ViewStateMode property of a page or a control has an effect only if the EnableViewState property is set to true. If the EnableViewState property is set to false, view state will be turned off even if the ViewStateMode property is set to Enabled.

    The default value of the ViewStateMode property for a page is Enabled. The default value of the ViewStateMode property for a Web server control in a page is Inherit. As a result, if you do not set this property at either the page or the control level, the value of the EnableViewState property determines view-state behavior.

    You can use the ViewStateMode property to enable view state for an individual control even if view state is disabled for the page. For more information about view state and control state, see the EnableViewState property.

    To disable view state for a page and to enable it for a specific control on the page, set the EnableViewState property of the page and the control to true, set the ViewStateMode property of the page to Disabled, and set the ViewStateMode property of the control to Enabled.

    0 讨论(0)
  • 2020-12-29 19:07

    Till ASP.NET 3.5 Version, Page Level view state control Property (EnableViewState) treat as highest priorities, means whether control level Property is True or False it doesn't change the behavior it sees page level Property. But in ASP.NET 4 Version, New Property ViewStateMode is used which has value

    1.Disabled - will disable the viewstate for that page or control(i.e if page level property is disable and control level property is enable now view state will work for control which was previously now working using EnableViewState).

    2.Enable - will enable the viewstate for that page or control(i.e if page level property is enable and control level property is disable now view state will work for not work for control).

    3.Inherit - will inherit the Property of page control Property.

    0 讨论(0)
提交回复
热议问题