Thanks to hints from @Șhȇkhaṝ and @am1r_5h and the suggests from here, namely
setting args.IsValid at the end of the code
I was able to perform validation on client by refactoring the validateDelete
function into this:
function validateDelete(sender, args){
var itemId = sender.dataset.itemid;
var isValid; // <- declare outer scope variable to hold the result
$.ajax({
async:false
// other settings omitted
success: function(jsonResult){
isValid = jsonResult.CanDelete; // <- set the result of ajax call
}
// Set args.IsValid at the end of the function.
args.IsValid = isValid;
});
}