The ASP.Net HiddenField control enables you to store the information at client side in the web browser that persists even after post back event of web page. Usually we use Session, ViewState or Cookies to maintain the state of the web page. The HiddenField control also provides the similar functionality to store the persistent data and maintains its state across post backs to the server. If session, view state or cookie methods are not available then you can use the HiddenField control to maintain the web page state. The ASP.Net HiddenField control renders as HTML input control with type attribute as "hidden". It does not appear physically in the graphical representation of web page but you can access it in the server code and get or set its value using C# code in the server end script.
Properties of ASP.Net HiddenField Control
The ASP.Net HiddenField control provides following properties that can be used to store the information at client side:
The Value property enables you to get or set the information that you want to store in the hidden field control. The visible property allows you to show or hide the HTML markup code of hidden field control in the source code. But if you will set the visible property to "false" then the ViewState will play its role to hold the value of hidden field instead.
HiddenField Control Event
The HiddenField control provides OnValueChanged event that is raised at the time value of hidden field control changes between the post back event of web page. You can get the updated value of control and display it or use it for further processing.
In the sample below we have used the ASP.Net HiddenField control to hold the clicks count of button control that will get incremeneted each time you will click the button control. Try the sample below to understand the working of ASP.Net HiddenField control: