What is viewstate and use of view state?

 Posted by Rajni.Shekhar on 4/10/2012 | Category: ASP.NET Interview questions | Views: 2805 | Points: 40

Viewstate is a client side state management technique or method. View state is a temprory storage media to store any value in page level only.

Viewstate is also used to maintain state of server controls like textbox during postbacks of a page.

In view state, you can also store structured data like arraylist, dataset etc.


Lets say there is data table filled with data.

DataTable dt=new Datatable();

//fill dt with data and store it in viewstate to persist its value in page during postbacks.

//store value in view state

//get value from view state
DataTable dt=(DataTable)ViewState["MyTable"];
string strUser=string)

Asked In: Many Interviews | Alert Moderator 

Comments or Responses

Login to post response