GeekInterview.com
Series: Subject: Topic:
Question: 10 of 348

What is the main role of View State?

what is the main purpose of view Sate.. like we can maintain value by session and etc but still we used view state why..???
Asked by: Con2Vini | Member Since Aug-2011 | Asked on: Feb 17th, 2012

View all questions by Con2Vini   View all answers by Con2Vini

Showing Answers 1 - 6 of 6 Answers
Same

Answered On : Mar 1st, 2012

View State is used to store the values in the current page.
Session is similar,but can hold values across the pages.

  
Login to rate this answer.
sumit

Answered On : May 21st, 2012

view state is a .net mechanism preserves the control & state on a webpage when user enter data page re-display view state for you by storing the appreciate information in hidden field on a form ;do not have to write code 2 implement viewsate;

  
Login to rate this answer.
Aakash

Answered On : Jun 8th, 2012

It belongs to state management system.It contains control specific information between the postback to the same page.

  
Login to rate this answer.

View State is one of the most important and useful client side state management mechanism. It can store the page value at the time of post back (Sending and Receiving information from Server) of your page. ASP.NET pages provide the ViewState property as a built-in structure for automatically storing values between multiple requests for the same page.

Example:

If you want to add one variable in View State,

Example: ViewState["Var"]=Count;
For Retrieving information from View State

Example:string Test=ViewState["TestVal"];

Sometimes you may need to typecast ViewState Value to retreive. As I give an Example to strore and retreive object in view state in the last of this article.

Advantages of view state?

This are the main advantage of using View State:

Easy to implement
No server resources are required
Enhanced security features ,like it can be encoded and compressed.
Disadvantages of view state?

This are the main disadvantages of using View State:

It can be performance overhead if we are going to store larger amount of data , because it is associated with page only.
Its stored in a hidden filed in hashed format (which I have discussed later) still it can be easily trapped.
It does not have any support on mobile devices.

  
Login to rate this answer.
jitendramin

Answered On : Feb 12th, 2013

View all answers by jitendramin

Viewstate is a Page label hidden variable which is used to maintain state of the control between postback. The values will be lost as soon as you move to new page. It is a client side state management where as Session is a server side state management. In case of session variables, values stored in session variable will be available for the whole session. This reduces the performance of the application. Hence we should use Session variables only in case you want to use a value across the page else you should always go for viewstate if you want to maintain a value for a page between postback.

Yes  1 User has rated as useful.
  
Login to rate this answer.
yogeshlcse

Answered On : Mar 14th, 2013

View all answers by yogeshlcse

View state is used to maintain the state of server controls during page postbacks.

  
Login to rate this answer.

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

Related Open Questions

Ads

Connect

twitter fb Linkedin GPlus RSS

Ads

Interview Question

 Ask Interview Question?

 

Latest Questions

Ads

Interview & Career Tips

Get invaluable Interview and Career Tips delivered directly to your inbox. Get your news alert set up today, Once you confirm your Email subscription, you will be able to download Job Inteview Questions Ebook . Please contact me if you there is any issue with the download.