Answered by:
Difference between Enable view state and ViewStateMode

Question
-
User604230926 posted
Hi
I have searched this one on Google, but still it is not clear to me!
For example womewhere I read that "EnableViewState enables the viewstate at page level"! But I see that even controls like buttons have "Enable viewstate"!
What I have concluded so far is:
-We can either turn on the enable view state at webconfig for all pages or similarly for a specific page and then we can turn off the viewstatemode of our specific controls' or we can leave it enables by choosing "Enable" or "Inherit"(Which acs identical to 'enable' in this example, since the page level is 'on') for ViewStateMode.
OR
-we can turn off EnableViewState and here the "Viewstatemode" does not have any effect!
Could you please confirm whether my understanding is right or not? If no please clarify it to me in a simple language.
Many thank
Thursday, January 3, 2013 8:13 PM
Answers
-
User790389354 posted
This is an excerpt from a book im reading at the moment. It may offer you an explanation.
Controls in ASP.NET have the ability to separate data state and control state. Previous versions of ASP.NET stored data and control state together. When a control's EnableViewState property was set to false, the control lost its appearence data along with the view state data. in the latest versions of ASP.NET (beyond 2.0), you can set a control's EnableViewState to false and you will turn of the property value data but not the control's appearence information. Of course, this means that a control might still be contributing to the size of the view state even when the EnableViewState property is set to false.
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Monday, January 7, 2013 10:25 PM -
User-606451722 posted
1. EnableViewState property has options, one--> turn off view state altogether, two -->Enable viewstate for the entire page
2. Turn off ViewState for the entire page and only enable for specified controls, use ViewStateMode property in conjunction with EnableViewState.
3. EnableViewState property only accepts true or false values and the default value is true,
4. ViewStateMode property have value of - Enabled, Disabled and inherit. Inherit is the default
5. ViewStateMode introduced in ASP.NET 4
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Wednesday, January 9, 2013 4:44 AM
All replies
-
Thursday, January 3, 2013 8:28 PM
-
User-2001205625 posted
Read the following articles
http://weblogs.asp.net/sreejukg/archive/2010/04/06/viewstatemode-in-asp-net-4-0.aspx
http://msdn.microsoft.com/en-us/library/system.web.ui.page.enableviewstate.aspx
Thursday, January 3, 2013 11:58 PM -
User604230926 posted
Let me give you an example:
I have a from, in which I have 1 text box and 1 button control. I have disabled the "EnableViewState" both in page directive and even in webconfig. Also, I have dissabled the "EnableviewState" and "ViewStateMode" of both my controls, but still whenevr I do postback, the textbox does not lose its value! How come?
<%@ Page Language="C#" EnableViewState="false" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="WebApplication301.WebForm1" %> <head runat="server"> <title></title> </head> <body> <form id="form1" runat="server"> <div> <asp:TextBox ID="TextBox1" runat="server" EnableViewState="False" ViewStateMode="Disabled"></asp:TextBox> <br /> <asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Button" EnableViewState="False" ViewStateMode="Disabled" /> <br /> </div> </form> </body> </html>
Friday, January 4, 2013 2:56 AM -
User790389354 posted
This is an excerpt from a book im reading at the moment. It may offer you an explanation.
Controls in ASP.NET have the ability to separate data state and control state. Previous versions of ASP.NET stored data and control state together. When a control's EnableViewState property was set to false, the control lost its appearence data along with the view state data. in the latest versions of ASP.NET (beyond 2.0), you can set a control's EnableViewState to false and you will turn of the property value data but not the control's appearence information. Of course, this means that a control might still be contributing to the size of the view state even when the EnableViewState property is set to false.
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Monday, January 7, 2013 10:25 PM -
User790389354 posted
i did some more searching this may explain it alot better.
http://support.microsoft.com/?id=316813Monday, January 7, 2013 10:51 PM -
User-606451722 posted
1. EnableViewState property has options, one--> turn off view state altogether, two -->Enable viewstate for the entire page
2. Turn off ViewState for the entire page and only enable for specified controls, use ViewStateMode property in conjunction with EnableViewState.
3. EnableViewState property only accepts true or false values and the default value is true,
4. ViewStateMode property have value of - Enabled, Disabled and inherit. Inherit is the default
5. ViewStateMode introduced in ASP.NET 4
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Wednesday, January 9, 2013 4:44 AM