leebee300
asked on
Checkbox RequiredFieldValidator
Does anybody know a simple way to ensure that a Checkbox is ticked, like using a RequiredFieldValidator for a Textbox ???????
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Culshaja,
please could you further explain point 1 if you dont mind, how would I go about this ????
thanks for anyhelp you could give me on this matter.
please could you further explain point 1 if you dont mind, how would I go about this ????
thanks for anyhelp you could give me on this matter.
You define a class as follows:
Imports System.Web.UI.WebControls
<ValidationPropertyAttribu te("Checke d")> _
public class myCheckBox Inherits CheckBox
end class
You can add your own custom properties and methods to the control. A good example of how the Validation property is set can be found at http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemwebuivalidationpropertyattributeclasstopic.asp
James :-)
Imports System.Web.UI.WebControls
<ValidationPropertyAttribu
public class myCheckBox Inherits CheckBox
end class
You can add your own custom properties and methods to the control. A good example of how the Validation property is set can be found at http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemwebuivalidationpropertyattributeclasstopic.asp
James :-)
why would you want to use RequiredFieldValidator for a checkbox?
checkbox, if checked has a value True, if unchecked has a value False. You don't need to user RequiredFieldValidator.
If you want to ensure that the value of a checkbox is always True, try a different validator
checkbox, if checked has a value True, if unchecked has a value False. You don't need to user RequiredFieldValidator.
If you want to ensure that the value of a checkbox is always True, try a different validator
Using a different validator still means that the control needs the ValidationPropertyAttribut e so that a validator will recognise it. You are right about using a different validator though. I would use a CustomValidator.
James :-)
James :-)
1. Inherit the checkbox control and set the property by using <ValidationPropertyAttribu
0r
2. Write your own custom validation code either as JavaScript or as code in the CodeBehind buttons onclick event.
Either way its not as simple as dragging a validation control.
Sorry,
James :-)