When i define the client handler for calendar OnDateSelected event i get strange action
as when i select date some dates after being set get change automatically to another date one or 2 days after the date i set
the code is as blow:
Hope I can get solution to such a problem as soon as possible
as when i select date some dates after being set get change automatically to another date one or 2 days after the date i set
the code is as blow:
<
telerik:RadDatePicker
ID
=
"calDOB"
runat
=
"server"
Culture
=
"en"
MinDate
=
"1900-01-01"
Width
=
"100%"
TabIndex
=
"5"
>
<
Calendar
runat
=
"server"
UseRowHeadersAsSelectors
=
"False"
UseColumnHeadersAsSelectors
=
"False"
ViewSelectorText
=
"x"
>
</
Calendar
>
<
DateInput
runat
=
"server"
DisplayDateFormat
=
"d/M/yyyy"
DateFormat
=
"d/M/yyyy"
TabIndex
=
"5"
>
</
DateInput
>
<
DatePopupButton
ImageUrl
=
""
HoverImageUrl
=
""
TabIndex
=
"5"
></
DatePopupButton
>
<
ClientEvents
OnDateSelected
=
"SelectedDateChanged"
/>
</
telerik:RadDatePicker
>
function SelectedDateChanged(sender,args) {
var PckrBirthDate = $find('<%=calDOB.ClientID %>');
var LblYears = $find('<%= TxtYears.ClientID %>');
var LblMonths = $find('<%= TxtMonths.ClientID %>');
var LblDays = $find('<%= TxtDays.ClientID %>');
var birthDate = PckrBirthDate.get_selectedDate();
if (birthDate != null) {
var calday = birthDate.getDate();
var calmon = birthDate.getMonth();
var calyear = birthDate.getFullYear();
getAge(calday, calmon, calyear, LblYears, LblMonths, LblDays);
}
else {
LblYears.set_value("");
LblMonths.set_value("");
LblDays.set_value("");
}
}
function getAge(date, month, year, yearControl, monthControl, dayControl) {
today = new Date();
dateStr = today.getDate();
monthStr = today.getMonth();
yearStr = today.getFullYear();
theYear = yearStr - year;
theMonth = monthStr - month;
theDate = dateStr - date;
var days = "";
if (monthStr == 0 || monthStr == 2 || monthStr == 4 || monthStr == 6 || monthStr == 7 || monthStr == 9 || monthStr == 11) days = 31;
if (monthStr == 3 || monthStr == 5 || monthStr == 8 || monthStr == 10) days = 30;
if (monthStr == 1) days = 28;
yearControl.set_value(theYear);
if (month <
monthStr
&& date > dateStr) {
yearControl.set_value(parseInt(yearControl.get_value()) + 1);
monthControl.set_value(theMonth - 1);
}
if (month <
monthStr
&& date <= dateStr) { monthControl.set_value(theMonth); }
else if (month == monthStr && (date < dateStr || date == dateStr)) { monthControl.set_value(0); }
else if (month == monthStr && date > dateStr) { monthControl.set_value(11); }
else if (month > monthStr && date <= dateStr) {
yearControl.set_value(yearControl.get_value()- 1);
monthControl.set_value(((12 - -(theMonth))));
}
else if (month > monthStr && date > dateStr) { monthControl.set_value(((12 - -(theMonth)))); }
if (date < dateStr) { dayControl.set_value(theDate); }
else if (date == dateStr) { dayControl.set_value(0); }
else { yearControl.set_value(yearControl.get_value() - 1); dayControl.set_value(days - (-(theDate))); }
}
Hope I can get solution to such a problem as soon as possible