Hi,
Label for example is a SPAN HTML Element at client-side and it can't keep
its state over postback, unless this state is stored to somewhere (or as
stated before, repopulated). So it uses ViewState, from where value of Text
property is fetched on postback. Of course, there's always the chance to
disable ViewState and take the classic route and populate the control
manually on every request.
But yes, the ViewState behaviour is more interesting with the controls that
do post along with the form. Take a TextBox for example. It in fact does not
need ViewState at all to keep its state, but it uses ViewState to raise
TextChanged event, that is, to detect if its state changed during a
postback. I've discussed how ViewState works in TextBox in a blog post:
http://blogs.aspadvice.com/joteke/archive/2004/03/15/767.aspx
This behaviour concerns pretty much the controls implementing
IPostBackDataHandler interface, the built-in controls which are posting HTML
elements at client-side, usually implement this interface. They check in
IPostBackDataHandler.LoadPostData implementation that what was posted, and
update their state accordingly. So their state goes mainly via posting, not
via ViewState, though there are exceptions, like DropDownList, which posts
the selection but not all items (DDL raises SelectedIndexChanged event based
on difference in selected item between previous and current
request/postback). So common behavior for these controls is, that they are
more independent what comes to ViewState, but they then utilize it bit
differently to aim for better usability and to help in development
scenarios.
--
Teemu Keiski
MCP, Microsoft MVP (ASP.NET), AspInsiders member
ASP.NET Forum Moderator, AspAlliance Columnist
http://blogs.aspadvice.com/joteke
Hi,
Thx fo reply ... but what i don understand is that even for those 'Some'
control(s) which can be retrived from
'Request.Form["ID"] ' - why is the viewState used AT-ALL. Even EACH Label
control on page has its own ViewState !!!
If sysstem has the information about all those fields that can be fetched
from 'Request.Form["ID"] ' then why should it by-default handle it ? - that
is eliminate its ViewState (which can be easily restored upon Postback !!!
So what do u think ?