Below is example for using a hidden field in asp.net :
aspx code :
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<input id="usrName" type="hidden" runat="server" />
<asp:Button runat="server" Text="Show Value"/>
</div>
</form>
</body>
</html>
aspx code :
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<input id="usrName" type="hidden" runat="server" />
<asp:Button runat="server" Text="Show Value"/>
</div>
</form>
</body>
</html>
codebehind :
using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
public partial class usingHiddenvariable : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
usrName.Value = "chandan";
}
else
{
showHiddenValue();
}
}
public void showHiddenValue()
{
Response.Write("<script language='javascript'>alert('Hidden value: "+ usrName.Value.ToString() +"');</script>");
}
}
Result :