I'm encountering an issue where a hidden field that I update via Javascript only reflects the new value after clicking a button twice. Surprisingly, I can view the updated hidden field value when inspecting it through 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;
}