views:

278

answers:

1

How can I clear the value of an asp:HiddenField control when the user hits the refresh button in the browser?

+2  A: 

In the load event (Page_Load, OnLoad) set hiddenVariableControl.Value = String.Empty.

If you are capturing this hidden variable's value for another event, you could do the following in the load event:

if( !Page.IsPostBack ) 
{
  hiddenVariableControl.Value = String.Empty;
}

This sets the value of the hidden variable to a blank string on refreshes, but postbacks (like a button event) would keep the value.

Forgotten Semicolon
hai, I will use that hidden field in a button click event... As you know when a click event is triggred Page load will be called at that time that hidden field will have no value if i set hiddenVariableControl.Value = String.Empty... Any option for this
Pandiya Chendur
when the user hits refresh button on the browser i want to clear the hidden field
Pandiya Chendur
Wrap the code in a Page.IsPostBack check.
Jason Berkan