Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

hidden field vs viewstate

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?
like image 504
Anyname Donotcare Avatar asked Jan 23 '11 09:01

Anyname Donotcare


People also ask

What is the difference between ViewState and hidden field?

In View state - not able to change the value by Client side code i.e java script. Hidden field - possible to change value by Client side code. Hidden field - You can store more than one value in hidden field,by serialized it.

Why do we use hidden fields?

A hidden field lets web developers include data that cannot be seen or modified by users when a form is submitted. A hidden field often stores what database record that needs to be updated when the form is submitted.

What is meant by ViewState?

View state is the method that the ASP.NET page framework uses to preserve page and control values between round trips. When the HTML markup for the page is rendered, the current state of the page and values that must be retained during postback are serialized into base64-encoded strings.

What is ASP hidden field?

HiddenField, as name implies, is hidden. This is non visual control in ASP.NET where you can save the value. This is one of the types of client-side state management tools. It stores the value between the roundtrip. Anyone can see HiddenField details by simply viewing the source of document.


2 Answers

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.

like image 200
Darin Dimitrov Avatar answered Sep 23 '22 18:09

Darin Dimitrov


A hidden field can be viewed in a pages HTML source whereas ViewState is, to say the least, obfuscated and depending on your .net version, can be encrypted to varying degrees.

asp.net viewstate encryption

Hidden field will be better in performance but provides no security and if the post data can be manipulated, be a lot easier to change the ViewState.

Session variables are a good alternative to these.

like image 38
PMC Avatar answered Sep 21 '22 18:09

PMC