difference between refreshing a page, postback and viewstate

D

Dan

Hi,

i'm not sure to understand the difference between refreshing the pagina by
clicking on 'refresh' in the browser and a postback.
What i think it is:
Suppose a page with a form containing a textbox and a dropdowlist: and a
button to start something n code-behind:
a refresh doesn't send any value back to the server but with a postback, the
values are sent?
But then, which role does Viewstate play in the postback proces?

Thanks for explaining me.
Dan
 
M

Mark Fitzpatrick

Dan,
A "Refresh" simply calls the last request made for a page. So, if
you just browsed to a page then hit refresh, it simply asks for that page
again.

A Postback is essentially an action on the page that sends
information back to the server. This is done using what is known as the Post
method (there is also a Get method and that's what the variables in the
querystring really are, get fields). So any activity that sends the page
back to the server is a post. Normally this is done by clicking on a button,
link button, image button, or through client-side javascript.

Now, when you do a "Refresh" after some activity that caused a post,
such as pushing a submit button, the page will "Refresh" the last activity.
So, if you push the submit button, then hit refresh it will send all the
post information again.

ViewState is essentially a client-side state information store,
giving you a way to save values and have them held in the page across many
postbacks. This is required since the web is a stateless environment and the
web server doesn't stay connected to the client browser after the page has
been completely fetched. You can save or edit viewstate variables, and also
get their information. One of the key things to remember is the viewstate
can only really be changed when you post back to the server. Let's say you
have a counter viewstate property. You set it to 1 when the user first
visits the page. You would expect it to increment when you hit the refresh
button but it doesn't. The reason is all you're doing is refreshing the
first request and setting the viewstate to one again. When you hit a button
and do a postback you'll be in a position where that viewstate variable
already exists and is set to one so now it can be incremented to 2.

Another thing to learn about the viewstate is it's not available in all
page events. The viewstate gets loaded a little later in the page lifecycle
so that it wouldn't be available in the oninit event, but is available by
the time the pageload event happens.
 
D

Dan

Hi Mark, thanks for your explanation.
One more thing: what's the default value (true or false)?
My web.config doesn't contain EnableViewState, nor any page ..
 

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,755
Messages
2,569,536
Members
45,007
Latest member
obedient dusk

Latest Threads

Top