We take pride in your success. We let our positivity drive us, day in and out. Talk to us at Mindfire to know us more.

Software Technology Tips

In ASP.NET HiddenField is an useful control which can be used to pass some values to client side during page postbacks. It has no user interface so it is only used to store hidden values. These hidden values can be used for Ajax call and other similar kind of functions.
 
As hiddenfield value can be changed by both client side & server side if you want to track whether the value is changed in the client side or not HiddenField provide some ways to do this check.
HiddenField provide one event none as OnValueChanged Which fires only if the hidden field value has been changed in the clientside.

<asp:HiddenField ID="hfDemo" runat="server" OnValueChanged="hfDemo_ValueChanged" />

protected void hfDemo_ValueChanged(object sender, EventArgs e)
{
// Write your cde logic
}
Hiddenfield can't cause postback so no postback will occur at the time of changing the value. But, when there is any postback then this event will executed if hiddenfield value is changed.
<asp:Button ID="btnChange" runat="server" Text="change" OnClientClick="javascript:document.getElementById('hfDemo').value = "10";" onclick="btnChange_Click" />
This function will check if any value has changed and call the event. By this way also you can track if the client is trying to tamper the HiddenField value.


Related Tags:

ASP.NET, HiddenField

Author: Aditya Acharya

top

ASP.NET

Let us Connect!

privacy

copyright (c) Mindfire Solutions 2007-2012. Login