Monday, March 26, 2012

call web service using ASP.NET AJAX with javascript without callback function

Hello,

I'm trying to create a custom validator with a ValidatorCalloutExtender all in an Update Panel. As everyone knows the callouts do not currently display automatically after a server post-back and will only work for custom validators which utilize client-side validation.

When i call the javascript function from validator callout extender i must return the args.IsValid method before the function ends. If i use a callback function and try to return the args.IsValid from there the validator can't react because the IsValid method is set to late.

In conclusion, with AjaxPro framework this example works

 function descriptionRequiredValidate(source, args){
var ajaxResult = FileAdmin.AjaxMethods.IsDescriptionRequired(...);
var descriptionText = document.getElementById("tbFileDescription");
var descriptionRequired = ajaxResult.value;
if(descriptionText.value =="" && descriptionRequired){
args.IsValid =false;
}
else{
args.IsValid =true;
}
}
As you can see no callback function is required but when i try to use the ASP.NET AJAX with a web service i can't read ajaxResult. Do i make a mystake somewhere or this tipe of response(without callback) only works with ajaxpro 

Your simplest path is to move your final declaration of validity to the OnSuccess handler of the service call.

No comments:

Post a Comment