I have a hidden field that I am updating via Javascript once I click a button, but when I try to access it on the code behind there is no value until I click the button the second time. I am able to see the hidden field value when I inspect it via the browser.
Default.aspx
<script type="text/javascript">
function LoadHtml(inputState, inputStateAbbr, inputProgramType, inputHealthCenter, inputCity) {
$.ajax({
url: omitted,
type: "POST",
async: false,
data: {
state: inputState,
stateAbbr: inputStateAbbr,
programType: inputProgramType,
healthCenter: inputHealthCenter,
city: inputCity
},
success: function(result) {
document.getElementById('DataHiddenField').value = result;
},
error: function (jqXHR, textStatus, errorThrown) {
//omitted
}
});
}
</script>
<asp:Button ID="Button1" runat="server" OnClick="Button1_OnClick" CssClass="top-buffer" Text="Compare Sites" />
<asp:HiddenField ID="DataHiddenField" runat="server" ClientIDMode="Static" />
Code Behind
protected void Button1_OnClick(object sender, EventArgs e)
{
RetrieveHtml();
}
private string RetrieveHtml(){
Page.ClientScript.RegisterStartupScript(this.GetType(), "MyKey1", "LoadHtml('Alabama', 'AL', 'Program Awardee Data', 'Alabama Regional Medical Services', 'Birmingham');", true);
return DataHiddenField.Value;
}