jquery - C# - HiddenField values changes after Button Click -
i have form captures few information and, using jquery, checks against database if company exists , sets hiddenfield value of yes or no.
textbox input follows
<asp:textbox id="txt_companyname" runat="server" cssclass="quote-contact-textbox-style" placeholder="company name" required="required"></asp:textbox>
jquery code check if company exists
$('#<%=txt_companyname.clientid%>').blur(function () { $.ajax({ url: 'fetch/verifyifcompanyexists.aspx', data: { companyname: $('#<%=txt_companyname.clientid%>').val(), }, success: function (result) { var data = result.split('|'); if (data[0] == "red") { alert('this company exists in crm'); $('#<%=hdn_custalreadyexists.clientid%>').val("yes"); } else { $('#<%=hdn_custalreadyexists.clientid%>').val("no"); } if (data[1] != "0") { $('#<%=hdn_existingcompanyid.clientid%>').val(data[1]); $('#<%=hdn_querydb.clientid%>').val("livedb"); } if (data[2] == "red") { alert('you have quoted customer'); } if (data[3] != "0") { $('#<%=hdn_existingcompanyid.clientid%>').val(data[3]); $('#<%=hdn_querydb.clientid%>').val('quotedb'); } } });
so if company exists, sets hdn_custalreadyexists value 'yes'. have checked (using alerts) field value indeed set 'yes' , is.
this button submit form
<asp:button id="btn_createquote" runat="server" text="create quote" onclick="btn_createquote_click" cssclass="quote_create_button" />
when check code behind, return value 'no' instead of 'yes'.
existingcustomer = hdn_custalreadyexists.value;
not sure why happening. can please let me know how resolve this?
thanks