In my ASP.NET AJAX UpdatePanel, there is a submit button with custom javascript validation that sets a global flag called _cancelGeneralSettingsUpdate
based on the validation results.
Everything works fine except when an invalid value is entered, corrected, and resubmitted. Even though the variable _cancelGeneralSettingsUpdate
is set to false
, the initializeRequest
function is not triggered before the page tries to postback via AJAX, resulting in a failed postback.
I need to ensure that postbacks are successful once the user corrects invalid input and submits again. Unfortunately, it seems like I am not properly connected to the PageRequestManager
pipeline after cancelling the postback. If I refresh the page, everything starts working again, but cancelling the postback using args.set_cancel(true);
puts me in a state where I cannot make further postbacks via AJAX until the page is refreshed.
Is there a way to re-enable postbacks or trigger the initializeRequest function to fire and set this before subsequent postbacks?
Below is some of the code I have. Please assume that _cancelGeneralSettingsUpdate
is correctly set before any postback attempts, 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);
}
}