473,383 Members | 1,997 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,383 software developers and data experts.

use required field validator for checkbox or checkboxlist

Expand|Select|Wrap|Line Numbers
  1. <asp:CheckBox ID="CheckBox1" runat="server" />
  2.  
  3.     <asp:RequiredFieldValidator ID="RequiredFieldValidator2" 
  4.         ControlToValidate="CheckBoxList1" runat="server" 
  5.         ErrorMessage="RequiredFieldValidator"></asp:RequiredFieldValidator>
  6.  
i have used this for checkbox

it gives error as

Control 'CheckBoxList1' referenced by the ControlToValidate property of 'RequiredFieldValidator2' cannot be validated.

how to use required field validator for checkbox or checkboxlist
Dec 7 '11 #1
1 23299
There are no fields in the check box list to fill , So RequiredFiledValidator doesn't work for that control.

You have to use "CustomValidator" for CheckBoxList...Check this code..

Expand|Select|Wrap|Line Numbers
  1. function checkTemp(sender,args)
  2. {
  3.      for(var i=0;i<=document.getElementById("CheckBoxList1").firstChild.children.length-1;i++)
  4.      {
  5.           if(document.getElementById("CheckBoxList1").firstChild.children(i).cells(0).children(0).checked)=='true'
  6.           alert('One is checked')
  7.           args.IsValid=true
  8.           return
  9.  
  10.      }
  11.      alert('None is selected')
  12.      args.IsValid=false
  13. }
  14.  
  15.  
  16. <asp:CustomValidator id="valcheckBoxTemp" runat="server" ClientValidationFunction="checkTemp" ErrorMessage="This is required control "></asp:CustomValidator>
Dec 17 '11 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: Do | last post by:
Hi, Has anybody run into problems with Page.IsValid? My errors show up when the fields aren't filled correctly, but my processing continues even if the page is invalid. I leave name and...
6
by: Paul | last post by:
I am trying to setup a field validator and tried using the control to validate set to a dropdown list box but did not seem to work. Is there anyway to set this up or do you need to use client side...
2
by: z. f. | last post by:
Hi, i have a field with required field validator. on the client side it's working. when i submit without the required field the page gets back because of not valid, but the message from the...
2
by: Asha | last post by:
greetings i want to use the required field validator control to validate a checkbox. here is the code implemented. <asp:RequiredFieldValidator ID="rfv" ControlToValidate="chkDistiAudit"...
1
by: Sam Collett | last post by:
Is there a way of having a required field validator check to see if at least one of a set of controls has information in it? I'm sure this can somehow be done using a custom validator, but would...
3
by: Skeptical | last post by:
Hello, I have a form and two buttons on it. Button1 submits the data to a database and RequiredFieldValidator is used to make sure all the required fields are filled up, the second button has a...
3
by: Mike Collins | last post by:
Is it possible to use a required field validator and have it make a user answer a comment field based on a drop down value picked? For instance, if the user selects "It was terrible", make them...
7
by: Newbie Coder | last post by:
How do I use a Required Field Validator control in ASP.NET 2.0 to validate an e-mail address entered into a textbox control because there is no VALIDATION EXPRESSION like in previous versions? ...
0
by: nimeshdotnet | last post by:
Hi All, I have a textbox whose readonly property is set to true. This textbox is also guarded by a required field validator. What i m doing that I have a calendar control whose on date selection i...
6
by: mathewgk80 | last post by:
Hi all, I have two textboxes, txtName and txtDescription. i added required field validator to both of them. I have a Gridview in the same page. In tht gridview, i have a template field...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.