| |
|
What is viewstate in ASP.NET?
The viewstate question should be well prepared before any ASP NET Interview.
Viewstate object is used to persist data of variables across postbacks.
It even existed in classic ASP. In ASP.NET, a variable's value is assigned to a
a viewstate object and then this is passed as a hidden variable
and then may be retrieved by a page after a postback. See the example below...
//Save the value in ViewState object before the PostBack
ViewState("SomeVar") = txtFirstName.text;
//Retrieve the value from ViewState object after the PostBack
String strFirstName = ViewState("SomeVar").ToString();
Note that Viewstate object's value is accessible only at page level. This means that
if a viewstate is created at page1.aspx, then it may be used only within page1.aspx after
the postback, and cannot be used by any other page.
To know how to pass values from one page to another,
Click Here.
Page Redirection
Values Between Pages
Worker Process
Page Life Cycle
Global Variables
Postback
Server Control
Viewstate
Send Email
Namespace
Localization
Event Handler
Validation
Global.asax
HttpHandler
Session
Cookie
EnableViewState
Smart Navigation
Web Farm
Dataset
Register
| |