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="<%=Clie ntID%>";
function checkDate(sende r,args){
cbDay=document. getElementById( client+'_day');
cbMonth=documen t.getElementByI d(client+'_mont h');
cbYear=document .getElementById (client+'_year' );
document.getEle mentById(client +'_err_msg').in nerHTML="";
if
(cbDay.selected Index>0&&cbMont h.selectedIndex >0&&cbYear.sele ctedIndex>0)
args.IsValid=tr ue;
else
{
if
(cbDay.selected Index==0&&cbMon th.selectedInde x==0&&cbYear.se lectedIndex==0)
args.IsValid=tr ue;
else
{
args.IsValid=fa lse;
document.getEle mentById(client +'_err_msg').in nerHTML="Invali d
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.Cli entID+"')";
year.attribute["onchange"]=setDate('"+day .ClientID+"','" +month.ClientID +"','"+year.Cli entID+"')";
On the aspx page, I have
<asp:dropDownli st runat="server" id="day" />
<asp:dropDownli st runat="server" id="month" />
<asp:dropDownli st 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:CustomVali dator ruen="server" id="cvDate" ControlToValida te="day"
ClientValidatio nFunction="chec kDate"
Display="non" ValidationGroup e="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="<%=Clie ntID%>";
function checkDate(sende r,args){
cbDay=document. getElementById( client+'_day');
cbMonth=documen t.getElementByI d(client+'_mont h');
cbYear=document .getElementById (client+'_year' );
document.getEle mentById(client +'_err_msg').in nerHTML="";
if
(cbDay.selected Index>0&&cbMont h.selectedIndex >0&&cbYear.sele ctedIndex>0)
args.IsValid=tr ue;
else
{
if
(cbDay.selected Index==0&&cbMon th.selectedInde x==0&&cbYear.se lectedIndex==0)
args.IsValid=tr ue;
else
{
args.IsValid=fa lse;
document.getEle mentById(client +'_err_msg').in nerHTML="Invali d
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.Cli entID+"')";
year.attribute["onchange"]=setDate('"+day .ClientID+"','" +month.ClientID +"','"+year.Cli entID+"')";
On the aspx page, I have
<asp:dropDownli st runat="server" id="day" />
<asp:dropDownli st runat="server" id="month" />
<asp:dropDownli st 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:CustomVali dator ruen="server" id="cvDate" ControlToValida te="day"
ClientValidatio nFunction="chec kDate"
Display="non" ValidationGroup e="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
Comment