How to use validation controls in this scenario ?

I

Ing. Rajesh Kumar

Hi everybody
Validation controls are great but i have a scenario where i do not know how
to use them so i am doing my validation on the server.
Let's say I have a Web Form with :
Two Textboxes : Textbox_1, Textbox_2
Two Checkboxes : Checkbox_1, Checkbox_2
A Button : btnSubmit

What I want is :
If Checkbox_1 is checked then Textbox_1 is required and it should contain
Email
If Checkbox_2 is checked then Textbox_2 is required and it should contain
numeric values
If both Checkboxes are checked then both Textboxes are required

If no Checkbox is checked then nothing is required.

I know it should be done using custom validator but cannot make it easily.
At present all my validation code is in the btnSubmit_Click method but that
way i cannot use the advantages of validation controls.

Thanks in advance
Raja
 
S

Sergey Poberezovskiy

Raja,

You could use some javascript to manipulate your
validation controls' enable# attribute in your checkbox
onclick event.

#
I do not have a VS on the computer I am currently on -
please check whether it's enable or enabled on your page
output.

Validation controls skip validation when the control is
not enabled.

Hope this helps.

-----Original Message-----
Hi everybody
Validation controls are great but i have a scenario where i do not know how
to use them so i am doing my validation on the server.
Let's say I have a Web Form with :
Two Textboxes : Textbox_1, Textbox_2
Two Checkboxes : Checkbox_1, Checkbox_2
A Button : btnSubmit

What I want is :
If Checkbox_1 is checked then Textbox_1 is required and it should contain
Email
If Checkbox_2 is checked then Textbox_2 is required and it should contain
numeric values
If both Checkboxes are checked then both Textboxes are required

If no Checkbox is checked then nothing is required.

I know it should be done using custom validator but cannot make it easily.
At present all my validation code is in the
btnSubmit_Click method but that
 

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,755
Messages
2,569,536
Members
45,014
Latest member
BiancaFix3

Latest Threads

Top