Calendar OnDateSelected Problem

2 posts, 0 answers
  1. Mohamed Elshahed
    Mohamed Elshahed avatar
    1 posts
    Member since:
    May 2010

    Posted 11 Apr 2011 Link to this post

    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:
    <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
  2. Mira
    Admin
    Mira avatar
    1124 posts

    Posted 14 Apr 2011 Link to this post

    Hello Mohamed,

    I tried to replicate the issue which you described, but to no avail.
    Attached to this post, you will find the code which I used for testing.

    Please, take a look at it and let me know if there are any differences at your end, which I may be leaving out.

    All the best,
    Mira
    the Telerik team

    Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.

Back to Top