Custom Validator to validate certain items checked in a checkboxli

G

Guest

If possible, how can I use a custom validator to check (client side) that if
a certain value was checked in a checkboxlist? So, if they checked "great" or
"good", comments are not required and if they checked "not so great" or
"awful", comments would be required before allowing the page to post.
 
G

Guest

Handle the ServerValidate method of your CustomValidator control as follows.
Set the args.IsValid equal to True if everything tests to be correct,
otherwise set it false.


Private Sub CustomValidator1_ServerValidate(ByVal source As
System.Object, ByVal args As
System.Web.UI.WebControls.ServerValidateEventArgs) Handles
CustomValidator1.ServerValidate
Try
If chkGreat.Checked Or chkGood.Checked Then
args.IsValid = True
ElseIf chkNotSoGreat.Checked Or chkAwful.Checked Then
args.IsValid = (txtComments.Text.Trim() <> "")
Else
args.IsValid = False
End If
Catch ex As Exception
'whatever
End Try
End Sub
 
G

Guest

Oh, and if you're specifically looking for client-side validation, if it
involves more than one control, you'll have to manually write some javascript
validation routine and call it on form submission.
 

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,744
Messages
2,569,482
Members
44,901
Latest member
Noble71S45

Latest Threads

Top