Solved

Checkbox RequiredFieldValidator

Posted on 2004-03-24
6
822 Views
Last Modified: 2008-01-16
Does anybody know a simple way to ensure that a Checkbox is ticked, like using a RequiredFieldValidator for a Textbox ???????
0
Comment
Question by:leebee300
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
6 Comments
 
LVL 7

Expert Comment

by:culshaja
ID: 10667167
The validation controls will only validate a control that has a ValidationPropertyAttribute set. This leaves you 2 options:

1. Inherit the checkbox control and set the property by using <ValidationPropertyAttribute("Checked")>

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 :-)
0
 
LVL 28

Accepted Solution

by:
mmarinov earned 45 total points
ID: 10667261
if you can affort it you can set the Autopostback property of the checkbox to True
then on every click the page will be submitted and you will know if the checkbox is clicked or not
if you don't want to use this you have to create javascript function

for examle:

create
<intpu type="hidde" runat="server" id="iCheckBoxIsClicked" value="false">
<script language="JavaScript">
function RememberClickingOnCheckBox()
{
 iCheckBoxIsClicked.value = "true";
}
</script>

then when you submit the page you will have in you Request.FOrm collection an item called iCHeckBoxIsClicked with value true or false

you have to set onclick="RememberClickingOnCheckBox()" to the checkbox

HTH
B..G
0
 

Author Comment

by:leebee300
ID: 10667777
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.
0
Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

 
LVL 7

Expert Comment

by:culshaja
ID: 10668113
You define a class as follows:

Imports System.Web.UI.WebControls

<ValidationPropertyAttribute("Checked")> _
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 :-)
0
 
LVL 35

Expert Comment

by:YZlat
ID: 10668155
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
0
 
LVL 7

Expert Comment

by:culshaja
ID: 10668385
Using a different validator still means that the control needs the ValidationPropertyAttribute so that a validator will recognise it. You are right about using a different validator though. I would use a CustomValidator.

James :-)
0

Featured Post

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…

624 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question