My AJAX call to a method in the code-behind seems to be unreliable even though I have everything set up correctly.
The JavaScript function utilizes PageMethods to invoke the method in the code-behind. While most of the time it works fine, occasionally it fails to call the method without any apparent pattern.
I'm puzzled as to why it sometimes doesn't work and there doesn't seem to be any consistent reason for the failures.
This issue occurs when clicking a link in a child window where you can repeatedly click the same link and successfully trigger the method multiple times before encountering a sudden failure.
The AJAX call in the parent window:
function Update(custtype) {
PageMethods.CustType(custtype)
}
The script in the child window that initiates the function:
<script type="text/javascript">
function sendval(value) {
window.parent.onSave();
window.parent.Update(value);
window.top.document.getElementById('txtCustomerType').value = value;
window.parent.location.reload()
}
</script>
The method in the parent window that is intermittently not called:
[System.Web.Services.WebMethod]
public static string CustType(string custtype)
{
HttpContext.Current.Session["CustType"] = "";
HttpContext.Current.Session["CustType"] = custtype;
return custtype;
}