CustomValidator for checkboxes?

G

Guest

Hi all...

I'm trying to use a custom validator for a group of checkboxes in order to
validate that at least 1 checkbox is checked before submitting the form.

I placed 2 checkbox controls in the form and a CustomValidator. When I saw
CustomValidator properties, the checkboxes aren't listed in ControlToValidate
properties. Only textboxes are listed. Also, I set the ValidationGroup for
the checkboxes to a name such as grpTipoEnvio and that name didn't appear in
that list either.

The JavaScript function is implemented this way:

function ValidaCheck(source, arguments)
{
var arguments.isValid = false;
var len = source.length;
if( len && len > 0 )
for( var i = 0; i < len; i++ )
arguments.isValid |= source.checked;
else
arguments.isValid = source.checked;
}


Is it possible to use this control to validate checkboxes? if not, how can I
accomplish this?

Thanks a ot in advance
Jaime
 
S

S. Justin Gengo

Jaime,

I created a CheckBoxListRequiredFieldValidator control. It has both
clientside and server side validation and operates just like a regular
required field validator except that you can specify how many checkboxes
need to be checked.

You may download the control for free from here:
http://www.aboutfortunate.com/default.aspx?page=checkboxlistvalidator

The control come as a Visual Studio 2003 project and is completely free to
use as you wish with all source code.

--
Sincerely,

S. Justin Gengo, MCP
Web Developer / Programmer

www.aboutfortunate.com

"Out of chaos comes order."
Nietzsche
 
G

Guest

Thanks Justin !

I have downloaded your control and after a few changes and corrections I
could use it.

- Changes

I use Visual Studio 2005 so I changed Me.Page.IsClientScriptBlockRegistered
(obsolete in 2005) to Page.ClientScript.IsClientScriptBlockRegistered

- Corrections

1.- in the first IF block of ClientScript method the word "verification" is
misspelled (it is written as checkboxlist_verifictation)

2.- in the first IF block, a call to RegisterClientScriptBlock was missing.

After those changes, validation works perfect!

Thanks again
Jaime

S. Justin Gengo said:
Jaime,

I created a CheckBoxListRequiredFieldValidator control. It has both
clientside and server side validation and operates just like a regular
required field validator except that you can specify how many checkboxes
need to be checked.

You may download the control for free from here:
http://www.aboutfortunate.com/default.aspx?page=checkboxlistvalidator

The control come as a Visual Studio 2003 project and is completely free to
use as you wish with all source code.

--
Sincerely,

S. Justin Gengo, MCP
Web Developer / Programmer

www.aboutfortunate.com

"Out of chaos comes order."
Nietzsche
Jaime Stuardo said:
Hi all...

I'm trying to use a custom validator for a group of checkboxes in order to
validate that at least 1 checkbox is checked before submitting the form.

I placed 2 checkbox controls in the form and a CustomValidator. When I saw
CustomValidator properties, the checkboxes aren't listed in
ControlToValidate
properties. Only textboxes are listed. Also, I set the ValidationGroup for
the checkboxes to a name such as grpTipoEnvio and that name didn't appear
in
that list either.

The JavaScript function is implemented this way:

function ValidaCheck(source, arguments)
{
var arguments.isValid = false;
var len = source.length;
if( len && len > 0 )
for( var i = 0; i < len; i++ )
arguments.isValid |= source.checked;
else
arguments.isValid = source.checked;
}


Is it possible to use this control to validate checkboxes? if not, how can
I
accomplish this?

Thanks a ot in advance
Jaime

 
S

S. Justin Gengo

Jaime,

Thanks for letting me know about the typo and missing method call. I'm
updating the code and will redeploy with the fixes. I'm starting to use
Visual Studio 2005 myself, but haven't converted my code library over yet.

--
Sincerely,

S. Justin Gengo, MCP
Web Developer / Programmer

www.aboutfortunate.com

"Out of chaos comes order."
Nietzsche
Jaime Stuardo said:
Thanks Justin !

I have downloaded your control and after a few changes and corrections I
could use it.

- Changes

I use Visual Studio 2005 so I changed
Me.Page.IsClientScriptBlockRegistered
(obsolete in 2005) to Page.ClientScript.IsClientScriptBlockRegistered

- Corrections

1.- in the first IF block of ClientScript method the word "verification"
is
misspelled (it is written as checkboxlist_verifictation)

2.- in the first IF block, a call to RegisterClientScriptBlock was
missing.

After those changes, validation works perfect!

Thanks again
Jaime

S. Justin Gengo said:
Jaime,

I created a CheckBoxListRequiredFieldValidator control. It has both
clientside and server side validation and operates just like a regular
required field validator except that you can specify how many checkboxes
need to be checked.

You may download the control for free from here:
http://www.aboutfortunate.com/default.aspx?page=checkboxlistvalidator

The control come as a Visual Studio 2003 project and is completely free
to
use as you wish with all source code.

--
Sincerely,

S. Justin Gengo, MCP
Web Developer / Programmer

www.aboutfortunate.com

"Out of chaos comes order."
Nietzsche
Jaime Stuardo said:
Hi all...

I'm trying to use a custom validator for a group of checkboxes in order
to
validate that at least 1 checkbox is checked before submitting the
form.

I placed 2 checkbox controls in the form and a CustomValidator. When I
saw
CustomValidator properties, the checkboxes aren't listed in
ControlToValidate
properties. Only textboxes are listed. Also, I set the ValidationGroup
for
the checkboxes to a name such as grpTipoEnvio and that name didn't
appear
in
that list either.

The JavaScript function is implemented this way:

function ValidaCheck(source, arguments)
{
var arguments.isValid = false;
var len = source.length;
if( len && len > 0 )
for( var i = 0; i < len; i++ )
arguments.isValid |= source.checked;
else
arguments.isValid = source.checked;
}


Is it possible to use this control to validate checkboxes? if not, how
can
I
accomplish this?

Thanks a ot in advance
Jaime

 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,985
Messages
2,570,199
Members
46,766
Latest member
rignpype

Latest Threads

Top