I have a custom validator to check if the entered number is unique or not. If the number is not unique it should return false.
the javascript code is like this:
function ValidatePAuthNo(sender, args) {
//args.IsValid = true;
var PAuthNo = $('[id$=tbPriorAuthNumber]').val();
$.ajax({
type: "POST",
url: "MedicaidPriorAuth.aspx/IsPAuthUnique",
data: JSON.stringify({ pAuthNo: PAuthNo }),
contentType: "application/json; charset=utf-8",
dataType: "json",
async: true,
error: function (response) {
alert(" An error occurred." + response.error);
},
success: function (data) {
if (data.d == false) {
//alert("P. Auth# already exists! Please enter new P. Auth #.");
$("[id$=lblError]").val("P. Auth# already exists! Please enter new P. Auth #.");
args.isValid = false;
} else {
$("[id$=lblError]").val("");
args.isValid = true;
}
}
});
return args.IsValid;
}
My Web method is returning correct value, however, problem is that return args.IsValid is called before ajax method. Am I doing something wrong here? If my approach is wrong what could be the correct approach to do this from client side?