The hidden field is a control that stores a
value but does not display that value to the user. It is like a label that had
a value, but was hidden. The hidden field is rendered as an HTML element. The hidden field can be used to store data that
needs to persist across multiple post backs. This control can come in handy
when other methods of storing data across post backs are not available, such as
session states and cookies.
The data is store on the client side. It store
only one value for variable and is saved as string. It is not visible in
browser but can see the stored data by using view source operation of the
browser.
Source Code:
<fieldset style="width:400px">
<legend>Hidden Field Explanation</legend>
<table>
<tr><td></td><td><asp:HiddenField ID="HiddenField1" runat="server" /></td></tr>
<tr><td></td><td><asp:Button ID="Button1" runat="server" Text="Button"
onclick="Button1_Click1" /></td></tr>
<tr><td></td><td><asp:Label ID="Label1" runat="server"></asp:Label></td></tr>
</table>
</fieldset>
Write
the below given code on .aspx.cs file(C#):
protected void Page_Load(object sender, EventArgs e)
{
HiddenField1.Value = "Hidden
Field Test";
}
protected void Button1_Click1(object sender, EventArgs e)
{
Label1.Text = HiddenField1.Value;
}
In VB:
Protected Sub Page_Load(sender As Object, e As System.EventArgs) Handles Me.Load
HiddenField1.Value = "Hidden
Field Test"
End Sub
Protected Sub Button1_Click1(sender As Object, e As System.EventArgs) HandlesButton1.Click
Label1.Text = HiddenField1.Value
End Sub
Advantages:
1. Server resources
are not required
2. Hidden fields are
easy to implement
3. All browsers support the hidden filed
4.
Useful to retain value between multiple post backs.
Disadvantages:
1. Hidden fields are not secure because data is stored
on client side.
2. Hidden field can store only one value.
3. Hidden field slow down the performance of page if
use large number of hidden fields
0 comments:
Post a Comment