Validators and JavaScript

N

Nathan Sokalski

When writing a validator by inheriting from the BaseValidator class, you
need to include a JavaScript function that takes one parameter (the span tag
generated by the validator) and returns true or false. This is great for
validators that can do validation client-side, but I am writing a validator
that requires server-side interaction with a database (it validates that a
value is unique). I would like to add the ability to have this validator use
ajax/client callbacks to display the validation result without a full
postback. I have used ajax and client callbacks many times in the past, but
my problem here is getting the result returned from the server to be applied
the same way the result from the JavaScript function assigned to the
evaluationfunction attribute of the generated span tag would be. Can anybody
help me here? Thanks.
 
B

bruce barker

this will not work without a little hacking. ajax is async (as name
imples) while validation is sync (called during the postback event).

your validator could return false (to stop the postback), start a ajax
call. when the ajax call returns, if all is ok, it could restart the
postback (which will call your validator again which should return true
this time). you could use ajax on the onblur event to call the server.
hopefully most of the time the server will return a result before the
use starts a postback.

also remember ajax will be a lot slower on real server talking to an
internet client then it is on you dev box (may take seconds to return).

-- bruce (sqlwork.com)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top