Welcome to BARMAGY Sign in | Join | Help

[SOS] Save our state – View State

 

 

For old fellows out there days of classic ASP things were simple, you render a form on the client the user presses few buttons eventually this page is posted to the server, to be more specific this browser is executing HTTP POST request to the server where the body of the request is the form data.

 

On the server side, what we used to do is to use Request(“”) to get items appended in the body payload posted to the server, or QueryString(“”) to get items appended to the URL.

 

With ASP.NET the model completely changed where the page is rendering is not controlled by you (default behavior, changeable when you want to). In fact you control it only by using controls (again that is a default behavior and it is changeable HTTP modules, HTML editing, intercepting PageRender/control events all these are means of doing that).  However the page itself to react to the user it goes to the server back and forth, generating what we understand as Post Back, however we only bind our controls and build then only when the page is first loaded, so a mechanism had to be invented where state of the control is saved to the client machine this is state is restored every time the page goes back and forth between browser and server.

 

This mechanism is a view state, a hidden field appended to the pay load of the POST request every time the page executes a post back action. (ever wondered how data grids are maintain their state when your page goes back and forth?)

 

So

-          View State:

o   Scope: Page Post Back

o   Storage: Client

o   Pros:

§  Very easy to use viewstate.add , viewstate.remove

§  Nothing is saved on server memory

o   Cons:

§  This data is saved to the client which makes your pages “fat” so watch out for its size if you are to deploy your app on slow networks.

§  DON’T TRUST VIEWSTATE, its data saved on the client! (even its encrypted, ciphered) it is just saved somewhere else.

Published Friday, February 16, 2007 11:31 AM by KAL

Comment Notification

If you would like to receive an email when updates are made to this post, please register here

Subscribe to this post's comments using RSS

Comments

No Comments

What do you think?

(required) 
required 
(required)