Within an ASP.NET AJAX UpdatePanel on my page I have a submit button which has some custom javascript validation applied which set a global _cancelGeneralSettingsUpdate
flag depending on the results of the validation.
Everything works unless you enter an invalid value, correct it, and resubmit. In this case the variable _cancelGeneralSettingsUpdate
is correctly set to false
but the initializeRequest
function is not called before the page attempts to postback via AJAX, causing the postback to fail.
I need to be able to have postbacks succeed once the invalid input has been corrected and the user clicks the submit button again. Unfortunately I do not seem to be properly wired into the PageRequestManager
pipeline once postback has been cancelled. If I refresh the page, everything works again, but cancelling the postback via args.set_cancel(true);
puts me into a state in which I cannot make further postbacks via AJAX until the page is refreshed.
How can I re-enable postbacks or cause the initializeRequest to fire and set this before subsequent postbacks?
I have attached some of my code. Assume _cancelGeneralSettingsUpdate
is set correctly before any attempt to postback, as I have verified this.
var _cancelGeneralSettingsUpdate = false;
function initializeRequest(sender, args) {
var pageRequestManager = Sys.WebForms.PageRequestManager.getInstance();
if (!pageRequestManager.get_isInAsyncPostBack() & args.get_postBackElement().id == '<%= UpdateWorkgroupGeneralButton.ClientID %>')
{
if (_cancelGeneralSettingsUpdate) {
args.set_cancel(true);
// Show error message
}
else {
args.set_cancel(false);
}
}
else {
args.set_cancel(false);
}
}