On my ASP.NET page, I am encountering an issue with a hidden field not being found during an asynchronous postback within an update panel. In the updatepanel_Load event, the following code is used:
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);
}
Essentially, hidden fields are added to a placeholder and their values are set with client-side scripting. However, upon an asynchronous postback, the FindControl method returns null because the placeholder1.Controls.Count is 0. This raises the question as to why the count is zero even though the hidden field was added prior to the postback.
Any assistance provided would be greatly appreciated.