Validating ASP.NET CheckBox (and similar) controls.
Uploader Comments (davidmbush)
All Comments (22)
-
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.
-
@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!!
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 1 year ago
@phil2415 Your question was? I hear your frustration, but no one can help you unless you ask a specific question.
davidmbush 1 year ago
@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 1 year ago
@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 1 year ago
@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 1 year ago
@phil2415 from here I'd need to see code. Sorry, I can't be of more help on this limited medium
davidmbush 1 year ago