Solved

Checkbox RequiredFieldValidator

Posted on 2004-03-24
6
798 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
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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

Normally the drop down box control found in the .Net framework tools is able to select just one data and value at a time, which is displayed on the text area.   But what if you want to have multiple values to be selected in the drop down box? As …
This article describes relatively difficult and non-obvious issues that are likely to arise when creating COM class in Visual Studio and deploying it by professional MSI-authoring tools. It is assumed that the reader is already familiar with the cla…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

757 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now