I know that this has been talked about before but I am still unsure.
When a asp.net page has a submit button clicked it sends the data in
the viewstate from controls on page to the server. The server sends a
response to same page with the same data. This is what is called a
postback, correct? A postback actually represents a round trip to and
back again from server, right? Now without the viewstate if I clicked
submit and the page didn't have viewstate enabled then the response
from the server would actually clear out the controls, correct?
Also what is HttpContext about? I read that it represents the data in
page, correct? When I reference this in code behind what are common
coding practices in using it?
Thanks,
JJ
Data in textboxes is not sent to the server via viewstate.
If you generate the content of a Label (which might be an "expensive"
operation), then the value assigned to that Label is remembered in
ViewState. On a postback the value for that label is restored from
ViewState, so you don't need to calculate is again.
HttpContext represents the "context" this page is called in. One very
useful application: if you want to access the Session (or Request or
Response) from within some class-library project, you can't use the
Session (Request, Response) properties that regular pages have. Instead
you can use HttpContext.Current.Session (etc).
Some things to watch out for: if a method is called by a timer (for
instance), instead of as a result of some HttpRequest, then there is no
HttpContext. Also in some cases Session could be null.
Hans Kesting