May 14, 2009

Store data in HiddenField

Data can be stored in a page using HiddenField control. The HiddenField does not show any output to the page but can be viewed from the page source of the page. Also, one of the limitations of the HiddenField is that only string data can be stored in the page.

The HiddenField control is declared as follows.

<asp:HiddenField ID="HiddenField1" runat="server" />

String values can be added to the HiddenField using the value attribute.

<asp:HiddenField ID="HiddenField1" runat="server" Value="some data" />

The page source shows how the HiddenField is generated.

<input type="hidden" name="HiddenField1" id="HiddenField1" value="some data" />
The HiddenField control can be accessed from code-behind of the page using it's ID attribute like any other control. To assign values to thecontrol, use the following code,

HiddenField1.Value = "some new data";

To find the value of the control, use the following code,

string data = HiddenField1.Value;


Pravesh Singh said...

Very informative post. It's really helpful for me and helped me lot to complete my task. Thanks for sharing with us. I had found another nice post over the internet which was also explained very well about Populate Grid Control From XML Document Easily, for more details of this post check out this link.....
HiddenField control in ASP.Net

Thanks everyone for your precious post!!

ANIL BABU Mandla said...

I have one requirement like this
I have a table CUSTOMER in that CUSTID,NAME,URL columns is thier
1 asp
2 weblog
3 google

My question is I opening perticular url based on CUSTID

I am Passing parameter Like That

corressponding URL data( It will open directly in browser

plz help me ...........
Thank you,

Reference: Shahed Kazi at