View State and Hidden Field
View State and Hidden Field
The View State is
client state mechanism in the ASP.Net statement management. The view state is
control it will be used to maintain the state of the control across the posted
back to the server.
The view state of a
page is, by default, placed in a hidden form field named __VIEWSTATE.
Every time it needs to
encryption and decryption (serialize and deserialize across the post backs).
The view state can be enabled by setting the
property called EnableViewState="true/false".
It can be set in the machine config/ web
config/ page directives/ control level.
By default it is false.
The view state also can store the data using the key and value combination. The
data will be serialized and stored in the hidden control you can view the
source code page and find the hidden control with _viewstate.
Drawbacks: - Increase the page payload (when you have grid with many
rows then everything has to be loaded and retain again with serialize and
deserilize) - Additional overhead while serialize and deserialize. - Increase
the memory allocation on the server.
The HiddenField control
provides you with a way to store information in the page without displaying it.
For example, you might store a user-preference setting in a HiddenField
control. To put information into a HiddenField control, you set itsValue
property to the value you want to store between postbacks. As with any other
Web server control, the information in a HiddenField control is available
during postback. The information is not persisted outside the page. The ASP.Net
Hiddenfield will be created like this. That HTML hidden field will be defined
like this. If you want to assign the value from the server side then
hidName.Value = "Testing";
Comments
Post a Comment