May 14, 2009

Store data in HiddenField

Data can be stored in a page using asp.net 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 asp.net 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;

2 comments:

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
CUSTID NAME URL
1 asp www.asp.net
2 weblog www.weblogs.asp.net
3 google www.google.com

My question is I opening perticular url based on CUSTID

I am Passing parameter Like www.Example.com?CUSTID=1 That

corressponding URL data(Ex:www.asp.net) It will open directly in browser

using asp.net........
plz help me ...........
Thank you,
anil

Reference: Shahed Kazi at AspNetify.com