RadCalendar.SelectedDate error

3 posts, 0 answers
  1. Jake
    Jake avatar
    15 posts
    Member since:
    Aug 2012

    Posted 05 Jul 2012 Link to this post

    hi.. I've been playing around with radcalendar and noticed that when I click a date it sets the value of selected date to the date as expected. However if I then click the same date the value of radcalendar1.SelectedDate is set to 01/01/0001 00:00:00 .

    If you click different days radcalendar.SelectedDate is always set to the correct value, it just seems to occur when you click the same date.

    is there a simple fix for this?

    <telerik:RadCalendar ID="RadCalendar1" Runat="server" CultureInfo="en-GB"
        MultiViewColumns="4" MultiViewRows="1"
            EnableMultiSelect="false" AutoPostBack="true"
        OnSelectionChanged="RadCalendar1_SelectionChanged" SelectedDate=""  
        ViewSelectorText="x" Skin="Windows7">
            <SpecialDays>
                <telerik:RadCalendarDay Date="" Repeatable="Today">
                    <ItemStyle CssClass="rcToday" />
                </telerik:RadCalendarDay>
            </SpecialDays>
  2. Eyup
    Admin
    Eyup avatar
    3005 posts

    Posted 06 Jul 2012 Link to this post

    Hi Jake,

    This is the default and expected behavior of RadCalendar since its SelectedDate cannot be assigned null, therefore it becomes the absolute possible minimal date. If you want to avoid the event when a day is deselected, please try to add the following condition:
    protected void RadCalendar1_SelectionChanged(object sender, Telerik.Web.UI.Calendar.SelectedDatesEventArgs e)
       {
           if (RadCalendar1.SelectedDates.Count > 0)
           {
              // execute custom logic here         
           }
       }

    That should do the trick.

    Regards,
    Eyup
    the Telerik team
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Jake
    Jake avatar
    15 posts
    Member since:
    Aug 2012

    Posted 06 Jul 2012 Link to this post

    ah then I guess I want to prevent deselect client side as per this article .. http://www.telerik.com/community/forums/aspnet-ajax/calendar/how-to-disable-date-deselect.aspx .. Thanks

    <script type="text/javascript">
            var date = null;
            function OnDateSelecting(sender, args) {
                var currentDate = args.get_renderDay().get_date();
                var newDate = new Date(currentDate[0], currentDate[1], currentDate[2]);
                if (args.get_renderDay().IsSelected && isDatesEquals(date, newDate)) {
                    args.set_cancel(true);
                }
            };

            function OnDateClick(sender, eventArgs) {
                var d = eventArgs.get_renderDay().get_date();
                date = new Date(d[0], d[1], d[2]);
            }

            function isDatesEquals(date1, date2) {
                if (date1.getFullYear() == date2.getFullYear() && date1.getMonth() == date2.getMonth() && date1.getDate() == date2.getDate()) {
                    return true;
                }
                else return false;
            }

        </script>    
        <telerik:RadCalendar ID="RadCalendar1" Runat="server" CultureInfo="en-GB"
        MultiViewColumns="4" MultiViewRows="1"
            EnableMultiSelect="false" AutoPostBack="true"
        OnSelectionChanged="RadCalendar1_SelectionChanged" SelectedDate=""  
        ViewSelectorText="x" >
        <ClientEvents OnDateSelecting="OnDateSelecting" OnDateClick="OnDateClick" />
Back to Top