Custom Validator to validate certain items checked in a checkboxli

Discussion in 'ASP .Net' started by =?Utf-8?B?TWlrZSBDb2xsaW5z?=, Aug 10, 2006.

  1. 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.
    =?Utf-8?B?TWlrZSBDb2xsaW5z?=, Aug 10, 2006
    #1
    1. Advertising

  2. 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.
    =?Utf-8?B?S2VpdGg=?=, Aug 10, 2006
    #2
    1. Advertising

  3. 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.
    =?Utf-8?B?S2VpdGg=?=, Aug 10, 2006
    #3
  4. 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.
    =?Utf-8?B?TWlrZSBDb2xsaW5z?=, Aug 10, 2006
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Grey
    Replies:
    3
    Views:
    13,618
    grish
    Oct 9, 2012
  2. yurps
    Replies:
    1
    Views:
    6,862
    rajeshthangarasu1983
    Feb 29, 2008
  3. Jay Douglas
    Replies:
    0
    Views:
    515
    Jay Douglas
    Feb 27, 2007
  4. Jay Douglas
    Replies:
    0
    Views:
    223
    Jay Douglas
    Feb 27, 2007
  5. Zvonko Bi¹kup

    Validate that at least one checkbox is checked

    Zvonko Bi¹kup, Mar 13, 2007, in forum: Javascript
    Replies:
    2
    Views:
    402
    -Lost
    Mar 13, 2007
Loading...

Share This Page