In this article we will introduce with HiddenField control in ASP.NET using C#.
HiddenField Example in ASP.NET using C#
The HiddenField control is used to store a value. It is rendered element. View state, session state and cookies are used to maintain the state of a web forms page. You can use HiddenField instead of view state, session state and cookies. In this example when you click the Hidden value button the label displayed a value. When you click the button again and again the value will decrease by 1.
HiddenField.aspx (Design page):

HiddenField.aspx (source code):
<%@ Page Title="" Language="C#" MasterPageFile="~/RoseindiaMaster.master" AutoEventWireup="true" CodeFile="HiddenField.aspx.cs" Inherits="HiddenField" %> <asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server"> </asp:Content> <asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server"> <div> <h2 style="color:Green">HiddenField in ASP.NET 4 , C#</h2> <asp:HiddenField ID="hiddenField" runat="server" /> <br /> <asp:Button ID="button" runat="server" Text="Hidden value" onclick="button_Click" /> <br /> <br /> <asp:Label ID="label" runat="server" Font-Bold="True" ForeColor="#000099" /> </div> </asp:Content>
HiddenField.aspx.cs (C# code file):
using System;
using
System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public
partial
class
HiddenField
: System.Web.UI.Page
{
protected
void
Page_Load(object
sender, EventArgs
e)
{
}
protected
void
button_Click(object
sender, EventArgs
e)
{
if
(hiddenField.Value ==
String.Empty)
hiddenField.Value =
"101";
hiddenField.Value = (Convert.ToInt32(hiddenField.Value)
- 1).ToString();
label.Text = hiddenField.Value;
}
}
Output:


[ 0 ] Comments