Thanks a lot for Alex's informative suggestions.
Hi Chris,
As Alex has mentioned, some certain webserver controls can still post their
values when we disable its viewstate. As for the TextBox control, it is
actual rendered as an <input type=text ...> html element when the page
render back to the client browser. And the TextBox's "Text" propery is
really be stored in the ViewState. However, when the page is post back ,
the TextBox's new value will be also post back because it is represent by
the "value" attribute of the <input type=text ..> element which is
accessable from the Request.Form[] collection. For example, if we have the
following TextBox in page
<asp:TextBox id="txt" runat=server Text="Initial value"></asp:TextBox>
when render to client, it is like below:
<input type="text" id="txt" name="txt" value="intial value" />
Then ,when the client user input new value in it, the "value" attribute's
value will change to the new input and when the page is post back, the new
value will be post together and we can use
Request.Form["txt"] to get it.
That's why we can get the textbox's value though the ViewState is disabled.
Then, what does the "Text" property (in the ViewState) do? Well, that's
anothe thing, let's have a look at the TextBox's serverside lifecycle:
When a page with a TextBox control is post back, (suppose the TextBox's ID
is "txt"), then,
In the page's LoadPostData event, it will get the TextBox's new input value
from the Request.Form[] collection as I mentioned above. Also, the page
will retrieve the TextBox's old value from the ViewState and compare them,
if different , it assgin the new Value to the "Text" property of the
TextBox and later the TextBox's TExtChanged event will be fired.. So if we
disable the ViewState , everytime the page will find that the new input it
different from the old value( because the old value in viewstate doesn't
exist ) and the TextChanged event will be fired.
In addition ,here is a good tech article which demonstrate the details of
the asp.net 's VIEWSTATE :
#Understanding ASP.NET View State
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnaspp/html
/viewstate.asp
Also, if you have interests , you can try using the .NET Reflector tool to
have a look at the TextBox's source code , that'll explain the question
more clearly
.
Hope all these helps. If you still have anything unclear, please feel free
to post here.
Regards,
Steven Cheng
Microsoft Online Support
Get Secure!
www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)