Added: 4 years ago
From: davidmbush
Views: 20,214
Sort by time | Sort by thread (beta)

Link to this comment:

Share to:

All Comments (22)

Sign In or Sign Up now to post a comment!
  • It is useful but i want to know the checkbox when it is bind with listview..

  • good one

  • Thanks, this was helpful. I got it to work using a checkboxlist in a wizard.

    Follow the above example, set args.isvalid in the ServerValidateEventArgs event. Use a foreach loop to loop through ListItems li in checkboxlist1. Then use an if statement to check if li.Selected is true. If true set args.Isvalid to true.

  • I just cannot get this to work. I already have a lot of RequiredField validators on my page and they work fine, with the ValildationSummary displaying all of the relevant error messages in one place. But even though I've specified the same ValidationGroup for the CustomValidator the error isn't displayed there. In fact, it won't return an IsValid value of False no matter what I do. Even when my code in the ServerValidate event is simply 'args.IsValid = False'!

  • @phil2415 Your question was? I hear your frustration, but no one can help you unless you ask a specific question.

  • @davidmbush I apologise, my question was just 'what am I doing wrong'? All of these controls are within a Wizard control and all of the standard RequiredField validators trigger when I click the 'Next' button, but the CustomValidator just doesn't seem to trigger at the same time. I added a line to report the validity of the checkbox and this doesn't appear until after all of the other validators have been satisfied, and even then it reports 'false' but lets the wizard advance anyway.

  • @phil2415 I'm going to guess that you don't have an event handler in the wizard to handle the "Next" that will check the "IsValid" property of the page. The other validations are working because they are using javascript. This is a server side validation so it doesn't trigger until you get to the server. You need something to prevent the "Next" from happening if the validations fail.

  • @davidmbush I do appreciate your help. As per your tutorial I added a 'If IsValid Then' line into the code behind for the next button but the problem is that while this prevents the wizard advancing if any of my RequiredField validators are invalid the CustomValidator doesn't seem to affect the IsValid status of the page itself, since even though the CustomValidator is reporting as 'False' the wizard advances anyway.

  • @phil2415 from here I'd need to see code. Sorry, I can't be of more help on this limited medium

  • @davidmbush Don't apologise, your help is very much appreciated. You put me on the right track and now I've figured it out. The page was 'invalid' but my code to prevent the wizard from advancing if this was the case was wrong. I've now got:

    If IsValid = False Then e.Cancel = True

    End If

    in the NextButtonClick event of the wizard. So now when I click the Next button the RequiredField validators kick in, then the page posts back and the CustomValidator does its thing.

    Thanks again!!

  • great work David. I make similar videos. Lets do something it.

  • Thank you. Very helpful!

  • .Net FAIL

    Control 'CheckBox27' referenced by the ControlToValidate property of 'CustomValidator1' cannot be validated.

  • You shouldn't be using the "ControlToValidate" property. It isn't needed and it WILL cause an error if you do. This was covered in the video

  • great tutorial, thanks

  • Do you have any examples of validating checkboxlists using a custom validator and vb?

  • thank u so much..great post

  • Excellent

  • Thanks!

    Gracias!

    from Argentina.

  • thank you

  • Thank you very much for the information, but why wouldn't you just use:

    args.IsValid = Checkbox1.Checked

    Seems much simpler.

    Anyway, thanks again.

  • Very nice

    thank you!

Loading...
Alert icon
0 / 00Unsaved Playlist Return to active list
    1. Your queue is empty. Add videos to your queue using this button:
      or sign in to load a different list.
    Loading...Loading...Saving...
    • Clear all videos from this list
    • Learn more