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..???

Questions by Con2Vini   answers by Con2Vini

Showing Answers 1 - 18 of 18 Answers

Same

  • 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.

  Was this answer useful?  Yes

sumit

  • 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;

  Was this answer useful?  Yes

Aakash

  • Jun 8th, 2012
 

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

  Was this answer useful?  Yes

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.

  Was this answer useful?  Yes

jitendramin

  • Feb 12th, 2013
 

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.

Give your answer:

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

 

Related Answered Questions

 

Related Open Questions