This is a migrated thread and some comments may be shown as answers.

RadCalendar.SelectedDate error

2 Answers 93 Views
Calendar
This is a migrated thread and some comments may be shown as answers.
Jake
Top achievements
Rank 1
Jake asked on 05 Jul 2012, 11:06 AM
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 Answers, 1 is accepted

Sort by
0
Eyup
Telerik team
answered on 06 Jul 2012, 02:07 PM
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.
0
Jake
Top achievements
Rank 1
answered on 06 Jul 2012, 07:02 PM
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" />
Tags
Calendar
Asked by
Jake
Top achievements
Rank 1
Answers by
Eyup
Telerik team
Jake
Top achievements
Rank 1
Share this question
or