postbacks

J

JJ

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
 
M

mattmorg55

You're right about postback ... note that the values of the controls
are restored from the viewstate on the server ... then you can
manipulate them before the viewstate gets serialized again and the
controls get rendered to the browser.

One bit of advice: don't get postback crazy because it is expensive.
Don't use postback for navigation between pages. Just use it for
submitting forms. And check out the new Atlas framework for reducing
full page round trips.

I would check out msdn2.microsoft.com for stuff on HttpContext.
 
H

Hans Kesting

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,583
Members
45,074
Latest member
StanleyFra

Latest Threads

Top