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;