Benefit of View State

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • developerquery
    New Member
    • Jun 2012
    • 17

    Benefit of View State

    As View state retains the state of a control when a .aspx page takes a round trip, but when I disable it then too the output is the same.
    Example:

    Code:
    <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
    <asp:Button ID="Button1" runat="server" Text="Submit" />
    I type test in the text box at run time and click the Submit button then the test value is visible in textbox, as by default internally View State is maintained by the server control textbox, when I disable View State of the textbox control then too its visible.So what is the benefit of disabling it.

    Code:
    <asp:TextBox ID="TextBox1" runat="server"EnableViewState="False"></asp:TextBox>
    <asp:Button ID="Button1" runat="server" Text="Submit" />
    Last edited by Rabbit; Dec 10 '12, 04:38 PM. Reason: Please use code tags when posting code.
  • Frinavale
    Recognized Expert Expert
    • Oct 2006
    • 9749

    #2
    The TextBox uses ControlState as well as ViewState.

    Control state is like ViewState...it is a hidden state.

    ControlState is used by controls to maintain their core behavioral functionality; while ViewState only contains information to maintain the control's UI contents.

    This means that if you disable view state on a control, or on the entire page, the control state will still be used.

    Check out this MSDN article that compares ControlState to ViewState.

    -Frinny

    Comment

    Working...