Hi there,
Once again, persitance of the TextBox.Text property has nothing to do with
ViewState (Just Me's example will work for Label or any non-input web server
control). TextBox control implements IPostBackDataHandler inetrface, that is
responsible for retreiving the data from posted Form (HTTP POST). On every
post back request (form is submitted with all input values i.e. by pressing
submit button), Text property gets its value from the submitted Form:
(this code represents exactly what happens behind the scenes)
protected virtual bool LoadPostData(string postDataKey, NameValueCollection
postCollection)
{
base.ValidateEvent(postDataKey);
string text1 = this.Text;
string text2 = postCollection[postDataKey];
if (!this.ReadOnly && !text1.Equals(text2, StringComparison.Ordinal))
{
this.Text = text2;
return true;
}
return false;
}
Everyone who has programmed in more *raw* enviroment like ASP knows what i'm
trying to explain. It's easier to understand on following example (copy and
paste it to a ASPX page):
<input type="text" id="testBox" name="testBox" value="<%=
Request.Form["testBox"] %>" />
<input type="submit" value="Do a Post Back"/>
as you can see there's no viewstate mechanizm it works exactly the same as
'Just me' presented. That's actually what happens behind the scene. But
remember it applies only to input type controls, for asp:Label Text is
actually restored from ViewState on every post back. So if you disable
ViewState this won't display "test" on postback:
<asp:Label runat=server id=label1/>
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
label1.Text = "test";
}
}
Hope it is clear now
Regards