[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Nathan Pickett

2/27/2004 7:44:00 PM

Aaron,

Give this a try, I think is what you are looking for! -Nate

##########
RadioButtonListRequiredFieldValidator.cs
##########

using System;
using System.Text;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace Validators {

public class RadioButtonListRequiredFieldValidator : BaseValidator {

protected override bool ControlPropertiesValid(){

return true;

}


protected override bool EvaluateIsValid() {

return this.EvaluateIsChecked();

}



protected bool EvaluateIsChecked() {

CheckBoxList _cbl = ( ( CheckBoxList ) this.FindControl( this .
ControlToValidate ) );

foreach( ListItem li in _cbl.Items ) {

if ( li.Selected == true ) {

return true;

}

}
return false;

}

protected override void OnPreRender( EventArgs e ){

if ( this.EnableClientScript ) { this.ClientScript(); }
base.OnPreRender( e );

}

protected void ClientScript() {
this.Attributes["evaluationfunction"] = "cb_vefify";

StringBuilder sb_Script = new StringBuilder();
sb_Script.Append( "<script language=\"javascript\">" );
sb_Script.Append( "\r" );
sb_Script.Append( "\r" );
sb_Script.Append( "function cb_vefify(val) {" );
sb_Script.Append( "\r" );
sb_Script.Append( "var val = document.all[document.all[\"" );
sb_Script.Append( this.ID );
sb_Script.Append( "\"].controltovalidate];" );
sb_Script.Append( "\r" );
sb_Script.Append( "var col = val.all;" );
sb_Script.Append( "\r" );
sb_Script.Append( "if ( col != null ) {" );
sb_Script.Append( "\r" );
sb_Script.Append( "for ( i = 0; i < col.length; i++ ) {" );
sb_Script.Append( "\r" );
sb_Script.Append( "if (col.item(i).tagName == \"INPUT\") {" );
sb_Script.Append( "\r" );
sb_Script.Append( "if ( col.item(i).checked ) {" );
sb_Script.Append( "\r" );
sb_Script.Append( "\r" );
sb_Script.Append( "return true;" );
sb_Script.Append( "\r" );
sb_Script.Append( "}" );
sb_Script.Append( "\r" );
sb_Script.Append( "}" );
sb_Script.Append( "\r" );
sb_Script.Append( "}" );
sb_Script.Append( "\r" );
sb_Script.Append( "\r" );
sb_Script.Append( "\r" );
sb_Script.Append( "return false;" );
sb_Script.Append( "\r" );
sb_Script.Append( "}" );
sb_Script.Append( "\r" );
sb_Script.Append( "}" );
sb_Script.Append( "\r" );
sb_Script.Append( "</script>" );
this.Page.RegisterClientScriptBlock( "RBLScript",
sb_Script.ToString() );

}

}

}


###############
TestValidator.aspx
################

<%@ Register TagPrefix="DNJValidators" Namespace="Validators"
Assembly="RadioButtonListRequiredFieldValidator" %>
<%@ import namespace="System.Data.SqlClient" %>

<script language="C#" runat="Server">



protected void Page_Load( object sender, EventArgs e ){



// Page.Controls.IndexOf(HtmlForm) form1.Attributes["OnSubmit"] =
"JavaScript:return(cb_vefify(document.all['cb']))";

if ( ! IsPostBack ) this.BindCBL();


}

protected void BindCBL(){

SqlConnection SqlCon = new SqlConnection(
"server=localhost;database=northwind;trusted_connection=true" );
SqlCommand SqlCmd = new SqlCommand( "SELECT TOP 10 ProductName, ProductID
FROM Products", SqlCon );

SqlCon.Open();
cb.DataSource = SqlCmd.ExecuteReader();
cb.DataTextField = "ProductName";
cb.DataValueField = "ProductID";
cb.DataBind();

}

</script>


<html>
<body>
<form runat="server">

<H3>RadioButtonList Validator</H3>

<!-- Summary -->
<asp:ValidationSummary
id="valSum"
DisplayMode="BulletList"
runat="server"
HeaderText="You must enter a value in the following fields:"
Font-Name="verdana"
Font-Size="8" />
<BR>
<!-- Summary -->

<P>

<!-- Our Validator -->

<B>You must select one item</B>
<DNJValidators:RadioButtonListRequiredFieldValidator
ID="valMessage"
ControlToValidate="cb"
RUNAT="SERVER"
EnableClientScript="true"
ErrorMessage="You must check at least one check box">
*
</DNJValidators:RadioButtonListRequiredFieldValidator>
<BR>
<asp:CheckBoxList runat="server" id="cb" />

<!-- Our Validator -->

<P>

<!-- Intrinsic Validator -->

<B>You must fill out</B>
<asp:RequiredFieldValidator
id="RF"
runat="server"
ControlToValidate="txt"
ErrorMessage="You must fill out text box">
*
</asp:RequiredFieldValidator>
<BR>
<asp:TextBox id="txt" runat="server" />

<!-- Intrinsic Validator -->

<p>

<asp:Button id="submit" Text="Submit" runat="server" />
</form>
</body>
</html>

"aaron" <aabbott@wcpn.org> wrote in message
news:5EC1C298-4CCC-4039-A76D-1E603EE7D362@microsoft.com...
> I have a web page form with a group of 6 checkboxes (using the
checkBoxList control) and I want to validate that the user checks at least
one item in the list.
>
> I have been looking for some good examples of how this can be done and can
not find a whole lot. Is there a way to do it with a custom validator?
Anyone have any examples or know of any links to examples. I have seen a
couple out there for checkbox but not checkBoxList.
>
> Thanks in advance, for your help!
>


14 Answers

brian

2/24/2012 1:10:00 AM

0

On Thu, 23 Feb 2012 16:40:21 -0500, Jim_Higgins
<gordian238@hotmail.com> wrote:

>On 2/23/12 3:09 PM, Gary wrote:
>> In middle Georgia last night the low was 64 degrees. Right now it
>> is 81 degrees. If I ever saw a February day reach 80 degrees, I
>> do not remember it.
>>
>> I was sitting outside in the sun about 2:00PM. It got so hot I had
>> to move to the shade. That is a new experience for this time of
>> year.
>
>Isn't global warming great :-)

Untill summer............

Jim Higgins

2/24/2012 1:46:00 AM

0

On 2/23/12 8:09 PM, brian wrote:
> On Thu, 23 Feb 2012 16:40:21 -0500, Jim_Higgins
> <gordian238@hotmail.com> wrote:
>
>> On 2/23/12 3:09 PM, Gary wrote:
>>> In middle Georgia last night the low was 64 degrees. Right now it
>>> is 81 degrees. If I ever saw a February day reach 80 degrees, I
>>> do not remember it.
>>>
>>> I was sitting outside in the sun about 2:00PM. It got so hot I had
>>> to move to the shade. That is a new experience for this time of
>>> year.
>>
>> Isn't global warming great :-)
>
> Untill summer............

I forgot about that. Oops

Earl Evleth

2/24/2012 8:55:00 AM

0

On 24/02/12 2:09, in article spodk7tsil8ieqnt4t5vgf1qgesio9k8us@4ax.com,
"brian" <bfunk850@cox.net> wrote:

>>


We just flipped from a very cold Feb, very warm January and to a warmer
end of Feb. We are in the grips of the North Atlantic Oscillation
which does goofy things at times. It is not evidence of global warming
which has to be judged on a very long time scale.

In Paris the historical high on this date was 20?C in 1990
and a record low of -12?C in 1955, we will run about 14?C today
which is 5?C above average. Two weeks ago we were 5?C under
average.


rumpelstiltskin

2/24/2012 12:18:00 PM

0

On Thu, 23 Feb 2012 17:57:54 -0500, Evelyn <evelyn.ruut@gmail.com>
wrote:

>On Thu, 23 Feb 2012 16:40:21 -0500, Jim_Higgins
><gordian238@hotmail.com> wrote:
>
>>On 2/23/12 3:09 PM, Gary wrote:
>>> In middle Georgia last night the low was 64 degrees. Right now it
>>> is 81 degrees. If I ever saw a February day reach 80 degrees, I
>>> do not remember it.
>>>
>>> I was sitting outside in the sun about 2:00PM. It got so hot I had
>>> to move to the shade. That is a new experience for this time of
>>> year.
>>
>>Isn't global warming great :-)
>
>
>At the moment it is 45 degrees here in the Catskills.
>
>Today I didn't even need a coat.
>
>Evelyn



I only wear a T-shirt above the waist, excluding coats,
and I'm always one of the last people to add a coat,
but this winter I think I've put on a coat fewer than five
times. It's the warmest winter I've ever experienced.
Yesterday and Today there were new record highs for
the day in a couple of towns in the Bay Area, and
that's been going on all winter. Some of the nudists
have been out on the plaza most of the time.

Evelyn

2/24/2012 3:27:00 PM

0

On Fri, 24 Feb 2012 04:18:06 -0800, rumpelstiltskin
<rumpelstiltskin@x.com> wrote:

>On Thu, 23 Feb 2012 17:57:54 -0500, Evelyn <evelyn.ruut@gmail.com>
>wrote:
>
>>On Thu, 23 Feb 2012 16:40:21 -0500, Jim_Higgins
>><gordian238@hotmail.com> wrote:
>>
>>>On 2/23/12 3:09 PM, Gary wrote:
>>>> In middle Georgia last night the low was 64 degrees. Right now it
>>>> is 81 degrees. If I ever saw a February day reach 80 degrees, I
>>>> do not remember it.
>>>>
>>>> I was sitting outside in the sun about 2:00PM. It got so hot I had
>>>> to move to the shade. That is a new experience for this time of
>>>> year.
>>>
>>>Isn't global warming great :-)
>>
>>
>>At the moment it is 45 degrees here in the Catskills.
>>
>>Today I didn't even need a coat.
>>
>>Evelyn
>
>
>
> I only wear a T-shirt above the waist, excluding coats,
>and I'm always one of the last people to add a coat,
>but this winter I think I've put on a coat fewer than five
>times. It's the warmest winter I've ever experienced.
>Yesterday and Today there were new record highs for
>the day in a couple of towns in the Bay Area, and
>that's been going on all winter. Some of the nudists
>have been out on the plaza most of the time.


This morning I woke up to find 3 inches of snow all over. Very
pretty. It's only 34 degrees so it should be turning to mush and
then water soon.

This has been an extraordinarily mild winter. Yesterday my husband
saw the great Blue Herons returning to the area nearby where they
nest. It's early for them.

Evelyn

rumpelstiltskin

2/24/2012 4:53:00 PM

0

On Fri, 24 Feb 2012 10:26:56 -0500, Evelyn <evelyn.ruut@gmail.com>
>On Fri, 24 Feb 2012 04:18:06 -0800, rumpelstiltskin
<snip>


>> I only wear a T-shirt above the waist, excluding coats,
>>and I'm always one of the last people to add a coat,
>>but this winter I think I've put on a coat fewer than five
>>times. It's the warmest winter I've ever experienced.
>>Yesterday and Today there were new record highs for
>>the day in a couple of towns in the Bay Area, and
>>that's been going on all winter. Some of the nudists
>>have been out on the plaza most of the time.
>
>
>This morning I woke up to find 3 inches of snow all over. Very
>pretty. It's only 34 degrees so it should be turning to mush and
>then water soon.
>
>This has been an extraordinarily mild winter. Yesterday my husband
>saw the great Blue Herons returning to the area nearby where they
>nest. It's early for them.
>
>Evelyn


I've mentioned that the only time I ever saw snow stay on
the ground overnight in San Francisco was in 1975, give or
take a year. I was driving to class the next morning along
winding Teresita Drive, and marvelling how beautiful all the
snow was on the hills. We have lots of hills in San
Francisco.

After a teenager in Massachusetts though, when the
snowplow always came down the street the same way,
so that the snow it was pushing piled up in the vacant
opportunity of the driveway that I'd just shovelled clear,
I'd pretty much had my fill of snow forever. It's nice to
see it once in a while, preferably from a distance, but
I'm not fond of being in it.

Evelyn

2/24/2012 6:12:00 PM

0

On Fri, 24 Feb 2012 08:52:39 -0800, rumpelstiltskin
<rumpelstiltskin@x.com> wrote:

>On Fri, 24 Feb 2012 10:26:56 -0500, Evelyn <evelyn.ruut@gmail.com>
>>On Fri, 24 Feb 2012 04:18:06 -0800, rumpelstiltskin
><snip>
>
>
>>> I only wear a T-shirt above the waist, excluding coats,
>>>and I'm always one of the last people to add a coat,
>>>but this winter I think I've put on a coat fewer than five
>>>times. It's the warmest winter I've ever experienced.
>>>Yesterday and Today there were new record highs for
>>>the day in a couple of towns in the Bay Area, and
>>>that's been going on all winter. Some of the nudists
>>>have been out on the plaza most of the time.
>>
>>
>>This morning I woke up to find 3 inches of snow all over. Very
>>pretty. It's only 34 degrees so it should be turning to mush and
>>then water soon.
>>
>>This has been an extraordinarily mild winter. Yesterday my husband
>>saw the great Blue Herons returning to the area nearby where they
>>nest. It's early for them.
>>
>>Evelyn
>
>
> I've mentioned that the only time I ever saw snow stay on
>the ground overnight in San Francisco was in 1975, give or
>take a year. I was driving to class the next morning along
>winding Teresita Drive, and marvelling how beautiful all the
>snow was on the hills. We have lots of hills in San
>Francisco.
>
> After a teenager in Massachusetts though, when the
>snowplow always came down the street the same way,
>so that the snow it was pushing piled up in the vacant
>opportunity of the driveway that I'd just shovelled clear,
>I'd pretty much had my fill of snow forever. It's nice to
>see it once in a while, preferably from a distance, but
>I'm not fond of being in it.


Hubby woke up feeling a little out of sorts today.... perhaps a virus
or something. Due to the snowfall, he had to shovel anyway. He
didn't feel like doing it, so he put it off till late. I made him
some matzo ball soup (chicken broth with dumplings) also known as
Jewish Penicillin (though neither of us is Jewish) and after lunch, he
went out with the snow blower and got the walk and driveway cleared.
We are both used to living with the changing seasons. This is only
the second snowfall we have had this winter and it was only a couple
of inches. But it would go and happen when he wasn't feeling up to
it!

Evelyn

High Miles

2/24/2012 6:21:00 PM

0

On 2/24/2012 12:12 PM, Evelyn wrote:
> On Fri, 24 Feb 2012 08:52:39 -0800, rumpelstiltskin
> <rumpelstiltskin@x.com> wrote:
>
>> On Fri, 24 Feb 2012 10:26:56 -0500, Evelyn<evelyn.ruut@gmail.com>
>>> On Fri, 24 Feb 2012 04:18:06 -0800, rumpelstiltskin
>> <snip>
>>
>>
>>>> I only wear a T-shirt above the waist, excluding coats,
>>>> and I'm always one of the last people to add a coat,
>>>> but this winter I think I've put on a coat fewer than five
>>>> times. It's the warmest winter I've ever experienced.
>>>> Yesterday and Today there were new record highs for
>>>> the day in a couple of towns in the Bay Area, and
>>>> that's been going on all winter. Some of the nudists
>>>> have been out on the plaza most of the time.
>>>
>>> This morning I woke up to find 3 inches of snow all over. Very
>>> pretty. It's only 34 degrees so it should be turning to mush and
>>> then water soon.
>>>
>>> This has been an extraordinarily mild winter. Yesterday my husband
>>> saw the great Blue Herons returning to the area nearby where they
>>> nest. It's early for them.
>>>
>>> Evelyn
>>
>> I've mentioned that the only time I ever saw snow stay on
>> the ground overnight in San Francisco was in 1975, give or
>> take a year. I was driving to class the next morning along
>> winding Teresita Drive, and marvelling how beautiful all the
>> snow was on the hills. We have lots of hills in San
>> Francisco.
>>
>> After a teenager in Massachusetts though, when the
>> snowplow always came down the street the same way,
>> so that the snow it was pushing piled up in the vacant
>> opportunity of the driveway that I'd just shovelled clear,
>> I'd pretty much had my fill of snow forever. It's nice to
>> see it once in a while, preferably from a distance, but
>> I'm not fond of being in it.
>
> Hubby woke up feeling a little out of sorts today.... perhaps a virus
> or something. Due to the snowfall, he had to shovel anyway. He
> didn't feel like doing it, so he put it off till late. I made him
> some matzo ball soup (chicken broth with dumplings) also known as
> Jewish Penicillin (though neither of us is Jewish) and after lunch, he
> went out with the snow blower and got the walk and driveway cleared.
> We are both used to living with the changing seasons. This is only
> the second snowfall we have had this winter and it was only a couple
> of inches. But it would go and happen when he wasn't feeling up to
> it!
>
> Evelyn
>
Can't you fill in for him if he's feeling crook ?
I love doing the snow stuff, but not everyone does.


rumpelstiltskin

2/24/2012 6:58:00 PM

0

On Fri, 24 Feb 2012 13:12:19 -0500, Evelyn <evelyn.ruut@gmail.com>
<snip>



>Hubby woke up feeling a little out of sorts today.... perhaps a virus
>or something. Due to the snowfall, he had to shovel anyway. He
>didn't feel like doing it, so he put it off till late. I made him
>some matzo ball soup (chicken broth with dumplings) also known as
>Jewish Penicillin (though neither of us is Jewish) and after lunch, he
>went out with the snow blower and got the walk and driveway cleared.
>We are both used to living with the changing seasons. This is only
>the second snowfall we have had this winter and it was only a couple
>of inches. But it would go and happen when he wasn't feeling up to
>it!
>
>Evelyn


I'm eating part of a matzo pancake on Pita bread with
Horseradish now. It's OK, but too bland. Matzo meal
really needs the chicken broth. I'm too lazy to go through
the finickiness of rolling up matzo balls, and it seems
pointless to me to roll it into balls anyway just for the sake
of somebody else's tradition, so I guess I'll just break up
the rest of the pancake and throw it into some chicken
broth later today or tomorrow. Maybe I should have
added a little pepper to the pita bread sandwich, as
well as the horseradish. I thought of that as I was eating
it, but didn't do it. Maybe I'll try that later.

Evelyn

2/24/2012 9:30:00 PM

0

On Fri, 24 Feb 2012 12:21:20 -0600, High Miles
<2blues1723@comcast.net> wrote:

>On 2/24/2012 12:12 PM, Evelyn wrote:
>> On Fri, 24 Feb 2012 08:52:39 -0800, rumpelstiltskin
>> <rumpelstiltskin@x.com> wrote:
>>
>>> On Fri, 24 Feb 2012 10:26:56 -0500, Evelyn<evelyn.ruut@gmail.com>
>>>> On Fri, 24 Feb 2012 04:18:06 -0800, rumpelstiltskin
>>> <snip>
>>>
>>>
>>>>> I only wear a T-shirt above the waist, excluding coats,
>>>>> and I'm always one of the last people to add a coat,
>>>>> but this winter I think I've put on a coat fewer than five
>>>>> times. It's the warmest winter I've ever experienced.
>>>>> Yesterday and Today there were new record highs for
>>>>> the day in a couple of towns in the Bay Area, and
>>>>> that's been going on all winter. Some of the nudists
>>>>> have been out on the plaza most of the time.
>>>>
>>>> This morning I woke up to find 3 inches of snow all over. Very
>>>> pretty. It's only 34 degrees so it should be turning to mush and
>>>> then water soon.
>>>>
>>>> This has been an extraordinarily mild winter. Yesterday my husband
>>>> saw the great Blue Herons returning to the area nearby where they
>>>> nest. It's early for them.
>>>>
>>>> Evelyn
>>>
>>> I've mentioned that the only time I ever saw snow stay on
>>> the ground overnight in San Francisco was in 1975, give or
>>> take a year. I was driving to class the next morning along
>>> winding Teresita Drive, and marvelling how beautiful all the
>>> snow was on the hills. We have lots of hills in San
>>> Francisco.
>>>
>>> After a teenager in Massachusetts though, when the
>>> snowplow always came down the street the same way,
>>> so that the snow it was pushing piled up in the vacant
>>> opportunity of the driveway that I'd just shovelled clear,
>>> I'd pretty much had my fill of snow forever. It's nice to
>>> see it once in a while, preferably from a distance, but
>>> I'm not fond of being in it.
>>
>> Hubby woke up feeling a little out of sorts today.... perhaps a virus
>> or something. Due to the snowfall, he had to shovel anyway. He
>> didn't feel like doing it, so he put it off till late. I made him
>> some matzo ball soup (chicken broth with dumplings) also known as
>> Jewish Penicillin (though neither of us is Jewish) and after lunch, he
>> went out with the snow blower and got the walk and driveway cleared.
>> We are both used to living with the changing seasons. This is only
>> the second snowfall we have had this winter and it was only a couple
>> of inches. But it would go and happen when he wasn't feeling up to
>> it!
>>
>> Evelyn
> >
>Can't you fill in for him if he's feeling crook ?
>I love doing the snow stuff, but not everyone does.


Alas, I am not able. If he was too sick to do it, I have the phone
number of a guy who will come out and plow it.

Evelyn