473,395 Members | 1,474 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,395 software developers and data experts.

CustomValidator

Hi,

I have a web user control that contains 3 dropdownlists
it's a date selector, so one contains the days, one the months and the last
the years.
Each of them starts with a blank value.
I want to control if the date is valid or blank (that means all the
dropdownlist have a blank value).

I need to add a customvalidator but I don't know on which control I have to
set it.

I create a javascript function to check the date.
here's the script
var client="<%=ClientID%>";
function checkDate(sender,args){
cbDay=document.getElementById(client+'_day');
cbMonth=document.getElementById(client+'_month');
cbYear=document.getElementById(client+'_year');
document.getElementById(client+'_err_msg').innerHT ML="";
if
(cbDay.selectedIndex>0&&cbMonth.selectedIndex>0&&c bYear.selectedIndex>0)
args.IsValid=true;
else
{
if
(cbDay.selectedIndex==0&&cbMonth.selectedIndex==0& &cbYear.selectedIndex==0)
args.IsValid=true;
else
{
args.IsValid=false;
document.getElementById(client+'_err_msg').innerHT ML="Invalid
date";
}
}
}

And more code to check if the date is correct if the user selects a month
that contains 30 or 31 days and adjust the number of days if the month is
february.
This function is called on an event that I add on the codebehind the month
and year dropdownlists like

month.attribute["onchange"]=setDate('"+day.ClientID+"','"+month.ClientID+"',' "+year.ClientID+"')";
year.attribute["onchange"]=setDate('"+day.ClientID+"','"+month.ClientID+"',' "+year.ClientID+"')";

On the aspx page, I have

<asp:dropDownlist runat="server" id="day" />
<asp:dropDownlist runat="server" id="month" />
<asp:dropDownlist runat="server" id="year" />

The codebehind binds the initial values for the dropdownlists.

My first idea was to set a customvalidator onto one dropdownlist
<asp:CustomValidator ruen="server" id="cvDate" ControlToValidate="day"
ClientValidationFunction="checkDate"
Display="non" ValidationGroupe="date" />
But it doesn't work, I get the "invalid date" if I change the day (of course
because the 2 other dropdownlists are blank).

How can I create the good customvalidator ?

Thanks for your help
Stan


May 8 '07 #1
3 2841
Hi,
>
I have a web user control that contains 3 dropdownlists
it's a date selector, so one contains the days, one the months and the
last
the years.
Each of them starts with a blank value.
I want to control if the date is valid or blank (that means all the
dropdownlist have a blank value).

I need to add a customvalidator but I don't know on which control I
have to set it.
For a CustomValidator, you are allowed to leave "ControlToValidate" blank.

Hans Kesting
May 8 '07 #2
Many thanks Hans, it works.
But I have another question about the same user control.
I ve put 2 of the same user controls onto a webform.

On this webform, I put a button with a validationgroup attribute.

On the customvalidator (of the user control) I set ValidationGroup with the
same value of the webform validationgroup.

When I submit my webform,
it seems the customvalidator of the 2nd usercontrol is checked.

Do I miss something on the user control ?
I m not sure that I have to set a validationgroup on the webform.

Stan

"Hans Kesting" <ne***********@spamgourmet.coma écrit dans le message de
news:c0**************************@news.microsoft.c om...
>Hi,

I have a web user control that contains 3 dropdownlists
it's a date selector, so one contains the days, one the months and the
last
the years.
Each of them starts with a blank value.
I want to control if the date is valid or blank (that means all the
dropdownlist have a blank value).

I need to add a customvalidator but I don't know on which control I
have to set it.

For a CustomValidator, you are allowed to leave "ControlToValidate" blank.

Hans Kesting

May 8 '07 #3
Ok, I ve found the issue...
Many thanks Hans, it works.
But I have another question about the same user control.
I ve put 2 of the same user controls onto a webform.

On this webform, I put a button with a validationgroup attribute.

On the customvalidator (of the user control) I set ValidationGroup with
the same value of the webform validationgroup.

When I submit my webform,
it seems the customvalidator of the 2nd usercontrol is checked.

Do I miss something on the user control ?
I m not sure that I have to set a validationgroup on the webform.

Stan

"Hans Kesting" <ne***********@spamgourmet.coma écrit dans le message de
news:c0**************************@news.microsoft.c om...
>>Hi,

I have a web user control that contains 3 dropdownlists
it's a date selector, so one contains the days, one the months and the
last
the years.
Each of them starts with a blank value.
I want to control if the date is valid or blank (that means all the
dropdownlist have a blank value).

I need to add a customvalidator but I don't know on which control I
have to set it.

For a CustomValidator, you are allowed to leave "ControlToValidate"
blank.

Hans Kesting

May 8 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: jcpmeticulus | last post by:
Hi I've spent the last day or so debugging a problem with a CustomValidator and am now totally stumped! Basically I use a number of CustomValidator's on my page, but have cut this down now to...
1
by: bill yeager | last post by:
I'm using the customvalidator in my web page. I get the following error when I try to run the web page: Unable to find control id 'lstRider' referenced by the 'ControlToValidate' property of...
2
by: Stephen Miller | last post by:
Can the CustomValidator be used to simply report unexpected errors, without requiring Client/Server validation? To explain, say you had a simple text box and button that did a Full-text Search of a...
3
by: Ronan Dodworth | last post by:
Hi there I'm having a little bit of a problem with my customvalidator control. The problem is the javascript runs fine on my local webserver IIS but not when I post it to the web hosting server....
3
by: philipl | last post by:
hi, i have a textbox in my edititemtemplate in my datagrid. I have created a customvalidator for it, when i update the row the appropiate function gets called to customvalidate but the problem...
1
by: SMG | last post by:
Hi All. My forms has two textboxes, 1 username, 2 password. Both has requiredfield validator it works fine when there is no input in these textboxes. And the errorMsg is shown in...
0
by: ghafranabbas | last post by:
This is how you use the customvalidator control in any INamingContainer interface control (Datagrid, DataList, DataRepeater, etc). 1. In the ItemTemplate, place your customvalidator 2. Set the...
1
by: Beffmans | last post by:
Hi I have defined an customvalidator on my TextBox: function clientvalidate(source, arguments){ { // even number? if (arguments.Value%2 == 0) arguments.IsValid = true; else
1
by: David | last post by:
I need help with CustomValidator in 1.1. I added the CustomValidator control and code as per the doc., (See below) However, the code is never executed. Is there an extra switch or setting to...
2
by: Jeff | last post by:
hey net 3.5 I have problem with a customvalidator. I enter values into the TextBox named "txt" and clicks on the save button (ibSave) then the TestValidate method get triggered. TestValidate...
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: 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: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.