Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Checkbox RequiredFieldValidator

Posted on 2004-03-24
6
Medium Priority
?
842 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 180 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
Veeam and MySQL: How to Perform Backup & Recovery

MySQL and the MariaDB variant are among the most used databases in Linux environments, and many critical applications support their data on them. Watch this recorded webinar to find out how Veeam Backup & Replication allows you to get consistent backups of MySQL databases.

 
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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …
Suggested Courses

782 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