S
Stan SR
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').innerHTML="";
if
(cbDay.selectedIndex>0&&cbMonth.selectedIndex>0&&cbYear.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').innerHTML="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
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').innerHTML="";
if
(cbDay.selectedIndex>0&&cbMonth.selectedIndex>0&&cbYear.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').innerHTML="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