hidden field vs viewstate

Anyname Donotcare picture Anyname Donotcare · Jan 23, 2011 · Viewed 21.1k times · Source

What is the difference when using

  • Hidden field vs View state?
  • When to use each one ?
  • Which one more secure?
  • Which is better in performance?
  • what are the alternatives?

Answer

Darin Dimitrov picture Darin Dimitrov · Jan 23, 2011

ViewState is stored in a hidden field and it contains information about the entire page. It can also be encrypted. Because the view state is always sent to the codebehind when performing Postbacks it is very practical as you always get the values. The drawback is that it can get really large if you start putting much information inside it and performance could start to suffer. For example in some AJAX requests you want to only send some small information to the server and if you used UpdatePanels the entire ViewState will be sent and it will contain information that is not necessary.