Class level fields are not persisted between postbacks. Use the Session state Collection to persist values. For persisting controls, you can use <asp:PlaceHolder />
.
EDIT:
If you are using the HiddenField
to just store a single value and access from server side and if it's not being accessed from client script, you can do something like this.
Remove your class level list.
if (!IsPostBack || triggeredRefresh.Value == "1")
{
Session["someValueKey"] = 0;
}
else if ( triggeredCheck.Value == "1" )
{
var x = Convert.ToInt32(Session["someValueKey"]);
}
if you do need a list of values, then you can do
if (!IsPostBack || triggeredRefresh.Value == "1")
{
Session["someValueKey"] = new List<int>{100,200};
}
else if ( triggeredCheck.Value == "1" )
{
var x = Session["someValueKey"] as List<int>();
}
if you do need it to be a control (to access from client script) you can do
if (!IsPostBack || triggeredRefresh.Value == "1")
{
HiddenField hiddenField = new HiddenField();
hiddenField.ID ="hiddenField1";
hiddenField.Value = "0";
placeHolder1.Controls.Add(hiddenField);
}
else if ( triggeredCheck.Value == "1" )
{
HiddenField hiddenField = placeHolder1.FindControl("hiddenField1") as HiddenField;
var x = Convert.ToInt32(hiddenField.Value);
}