Custom validator for a pair of controls

E

Erik Cruz

Hi.

I have a page that uses 4 textboxes where my user can input dates. Before
submit data, I need to test to see if the user filled at least two of these
textboxes. I can easily test this using simple javascript, but I am trying
to do this using a custom validator control. But as far as I know, the
validator tests just one control, not a pair of controls, as I need. Is it
possible to create a custom control for this situation?

TIA,
Erik Cruz
 
T

Teemu Keiski

Hi,

you can check multiple controls with CustomValidator. If you leave
ControlToValidate property to blank, CustomValidator runs the server-side
and client-side validation once per roundtrip (client-side before submitting
and server-side while postbacking as usual). It means the CustomValidator
isn't tied to the control and you can validate anything you want with it
(also blank controls or conditional validation). Certainly you need to refer
to the controls you validate in validion functions but that shouldn't be
hard.
 
F

fritz

Teemu said:
Hi,

you can check multiple controls with CustomValidator. If you leave
ControlToValidate property to blank, CustomValidator runs the server-side
and client-side validation once per roundtrip (client-side before
submitting and server-side while postbacking as usual). It means the
CustomValidator isn't tied to the control and you can validate anything
you want with it (also blank controls or conditional validation).
Certainly you need to refer to the controls you validate in validion
functions but that shouldn't be hard.
I am confused, is there not a problem with the label?. I thought the custom
validator used a label with a specific id.
 
T

Teemu Keiski

Are you somehow confusing validators that are done by using built-in
CustomValidator and then custom validator controls which are developed by
inheriting from BaseValidator? The built-in CustomValidator can work the way
I described (without ControlToValidate property)

Here is about the CustomValidator I was talking about:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnaspp/html/aspplusvalid.asp


--
Teemu Keiski
MCP, Microsoft MVP (ASP.NET), AspInsiders member
ASP.NET Forum Moderator, AspAlliance Columnist
http://blogs.aspadvice.com/joteke
 
E

Erik Cruz

Thanks Teemu, it worked :)

Maybe you can help me with another issue. My users type dates using the
format DD/MM/YYYY. How can I validate these dates in server-side code,
regardless of the format they are using?

Thanks again for your time.

Erik Cruz
 

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

No members online now.

Forum statistics

Threads
473,754
Messages
2,569,521
Members
44,995
Latest member
PinupduzSap

Latest Threads

Top