Living .NET...

Musings on .NET, and the like - Manoj G [MVP, Connected Systems Developer]

ViewState (De)mystification

In about of a year of .NET development, I had somehow stayed away from the nitty-gritties of ASP.NET. Today, out of the blue, I got this urge to create a custom composite control. After an inevitable struggle, I did manage to do what I wanted to. In the process, I came to know that my knowledge of ViewState was incomplete (crappy in other words) and later got enlightened by this brilliant article written by Paul Wilson, an ASP.NET MVP: ViewState: All You Wanted to Know.

Here's what I understand (in brief): ViewState would contain only that information/properties about controls that are lost after the page is dispatched to the browser. That is, those properties that are not available when post back happens. For example, formatting and style information etc. With this thought in mind, I browsed through the properties of  (System.Web.UI.WebControls) TextBox control using Reflector, and I was surprised to see that the Text property was stored in ViewState too. I wondered why. Text is a property that does not need to be stored in ViewState as this is available through the Form collection and the value will be replaced with the Form value when Postback data is processed before the Load Event.

If someone knows why, please do let me know!!

 
Posted: Fri, Nov 21 2003 19:23 by Manoj G | with 3 comment(s)
Filed under:

Comments

Manoj G said:

This is so the previous version can be compared with the version in the form collection to determine if the TextChanged event needs to be fired.
# September 29, 2004 3:21 AM

Dave Reed said:

It's also because, say you have the textbox in a placeholder or panel that is only visible at certain times during the usage of the control. Without viewstate the textbox would lose its value if the users posts the form while it is not visible.
# February 18, 2006 11:12 AM

Manoj G said:

Well, I got the clarification from the man himself..Paul Wilson. The Text property of the Textbox control is stored in ViewState cos it is required by the OnChnage server side event.
# August 30, 2006 12:23 AM
Leave a Comment

(required) 

(required) 

(optional)

(required)