Why does the page keeps its previous state if EnableViewState is set to false?
-
27 Temmuz 2012 Cuma 11:33
A very basic question, in a very simple scenario:
In trying to understand the Web Forms model page lifecycle and the View State mechanism implementation of a way to keep page states,
I have the following scenario: a blank page, with a text box and a button.
Why is it that if I set the page EnableViewState property to False, the contents I put in the text box are kept after hitting the button and thus generating a postback? The only way, as far as I understand, that that could happen is if the server side could have any mechanism of pointing out - after the creation of all the page objects, as defined in the aspx file - from scratch, at every new round trip to the server - whether some of this objects have had their properties changed - and in such cases apply them after the Page initialization stage completes.
However, after reading aware of the confusion about EnableViewState and ViewStateMode, I understand that... ViewStateMode is subjugated to EnableViewState, and if the latter is set to false, no object in the page is allowed to store its state.
With that being said - is it not exactly what is happening in the scenario below? So where does the content of the text box could possibly come from !?
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="WebApplication2.WebForm1" EnableViewState="false"%> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title></title> </head> <body> <form id="form1" runat="server"> <div> <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox> <br /> <asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Button" /> </div> </form> </body> </html>
Tüm Yanıtlar
-
27 Temmuz 2012 Cuma 12:11
can you check, the EnableViewState property of the page whether it is true or false, not the textbox control. Also, control state may also store the value http://msdn.microsoft.com/en-us/library/1whwt1k7.aspx
regards
joon
-
27 Temmuz 2012 Cuma 12:37
Thanks for replying, Joon.
As you can see in the code sample I posted, EnableViewState is set to false. And I did make any changes to view state at control levels.
-
27 Temmuz 2012 Cuma 12:50
Please read the article in following URL There clearly said to the view state life cycle.
http://msdn.microsoft.com/en-us/library/ms972976.aspx
With Thanks and Regards
Sambath Raj.C
click "Proposed As Answer by" if this post solves your problem or "Vote As Helpful" if a post has been useful to you
Happy Programming!- Yanıt Olarak İşaretleyen Bob ShenMicrosoft Contingent Staff, Moderator 03 Ağustos 2012 Cuma 15:01