![]() |
Custom Validator to validate certain items checked in a checkboxli
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. |
RE: Custom Validator to validate certain items checked in a checkboxli
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 "Mike Collins" wrote: > 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. |
RE: Custom Validator to validate certain items checked in a checkboxli
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. "Mike Collins" wrote: > 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. |
RE: Custom Validator to validate certain items checked in a checkb
Thanks...that helps with the server side and will help me think out the rest.
"Keith" wrote: > 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 > > "Mike Collins" wrote: > > > 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. |
| All times are GMT. The time now is 07:19 AM. |
Powered by vBulletin®. Copyright ©2000 - 2013, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.