Solved

Checkbox RequiredFieldValidator

Posted on 2004-03-24
6
811 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
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 
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

MIM Survival Guide for Service Desk Managers

Major incidents can send mastered service desk processes into disorder. Systems and tools produce the data needed to resolve these incidents, but your challenge is getting that information to the right people fast. Check out the Survival Guide and begin bringing order to chaos.

Question has a verified solution.

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

Suggested Solutions

Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
Finding and deleting duplicate (picture) files can be a time consuming task. My wife and I, our three kids and their families all share one dilemma: Managing our pictures. Between desktops, laptops, phones, tablets, and cameras; over the last decade…

739 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