Subscribe

RSS Feed (xml)

Reading and Storing Data in ViewState

The ViewState collection provides an easy way to maintain values on a particular Web


Form across postbacks.This collection is stored as a hidden form field, and thus all data


stored in ViewState is passed to and from the client on every request.You access it using


syntax similar to what you have seen for the Session and Application collections:


ViewState("UserName")="UserNameTextBox.Text"


UserNameLabel.Text = ViewState("UserName")


Comments


By default,Web controls that do not post back values will maintain their state automatically


using ViewState.This can be controlled individually for each control or globally for


each page by setting


EnableViewState to true or false as desired (either for a given


control or in the page directive).The amount of space a control occupies in ViewState


can easily be determined from the control tree section of the trace output.

No comments:

Archives

Variety in the Web World