Hidden Fields


The HiddenField control enables a developer to store a non-displayed value. It is used to store a value that needs to be persisted across posts to the server. It is rendered as an <input type="hidden" /> element. Normally view state, session state, and cookies are used to maintain the state of a Web Forms page. However, if these methods are disabled or are not available, you can use the HiddenField control to store state values.
Note that because the value of a HiddenField is rendered to the client browser, it is not suitable for storing security-sensitive values.
To specify the value for HiddenField a control, use the Value property. You can provide a routine that gets called everytime the value of the HiddenField control changes between posts to the server by creating an event-handler for the ValueChanged event.

HiddenField1_cs.aspx

Web
<%@ Page Language="C#" %>
<script language="C#" runat="server">
  protected void Button1_Click( object sender, EventArgs e ) {
  if ( HiddenField1.Value == "" )
   HiddenField1.Value = "0";
  // Increment the hidden field value by 1.
  HiddenField1.Value = (Int32.Parse( HiddenField1.Value ) + 1).ToString( );
  Label1.Text = HiddenField1.Value;
 }
</script>

<html>
 <body> 
  <form runat="server">
   <h3>HiddenField</h3>
   <asp:HiddenField id="HiddenField1" runat="Server" />
   <asp:Button id="Button1" Text="Click Me"
     onclick="Button1_Click" runat="server" />
   Clicked <asp:Label id="Label1" Text="0" runat="server" /> times
  </form>        
 </body>
</html>