Custom Validator

G

Guest

Can I create a generic Javascrip custom validator in which I can pass
multiple parameters? Looking at examples, it does not appear that I can. I
want to create a custom validator which will look at the value of two
controls and depending on those values either set the "style" of another
control to either visible or invisible.

Since the code is generic, I want to pass the names of the three controls to
the javascript routine....sounds like I can only pass the name of the control
to which the Validation control is associated with....Is this correct?

So I can not write a generic routine as I have described? I have to write a
"specific" non-generic routine in which the other 2 control names are hard
coded in the javascript code?
 
P

Peter Blum

The client-side function for customvalidator has a strict definition:
function ValidationFunctionName(source, arguments)
where source is the object that contains the validator (its a <span> tag)
and arguments contains the value of ControlToValidate and the IsValid
property.

Microsoft uses an interesting technique in this validator to get to its
ControlToValidate. You can use it too.
They do this:
Validator.Attributes.Add("ControlToValidate",
controltovalidateobject.ClientID) (controltovalidateobject is a reference
to the control object)
Then they access it like this on the client-side:
var vFld = document.all[source.ControlToValidate]; // case sensitive!

You just need to come up with your own unique name for each control. Be
aware that this is not XHTML compliant.

--- Peter Blum
www.PeterBlum.com
Email: (e-mail address removed)
Creator of "Professional Validation And More" at
http://www.peterblum.com/vam/home.aspx
 

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,773
Messages
2,569,594
Members
45,125
Latest member
VinayKumar Nevatia_
Top