How might I clear a hiddenfield value when the page is refresh in ASP.NET?

6.6k Views Asked by At

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

1

There are 1 best solutions below

2
On BEST ANSWER

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.