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

Disable selected date on RadCalendar?

3 Answers 269 Views
Calendar
This is a migrated thread and some comments may be shown as answers.
Tom
Top achievements
Rank 1
Tom asked on 17 Jun 2013, 10:18 PM
I'm using SelectedDate from the RadCalendar to display local events from a database using a listview and sqldatasource.  It works fine unless I click the same date twice.  The SelectedDate is then set to 1/1/0001 12:00:00 AM and I get the error "SqlDateTime overflow. Must be between 1/1/1753 12:00:00 AM and 12/31/9999 11:59:59 PM".

I read that selecting one date causes the previously selected date to become unselected, so I understand why it's happening, I just can't find a workaround.  

Is there a way to make the currently selected date inactive (unclickable)?  Or, can I check if the user selected the same date?

I tried using Calendar1_SelectionChanged but can't find a way to get the SelectedDate which is really unselected.  The FocusedDate is set to today's date, so I can't use it.

<telerik:RadCalendar ID="Calendar1" runat="server" EnableMultiSelect="false" ShowRowHeaders="false" AutoPostBack="true" Skin="MetroTouch" RenderMode="Lightweight"> </telerik:RadCalendar>
 
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:MyConnString %>">
    <SelectParameters>
        <asp:ControlParameter ControlID="Calendar1" Name="calendar1" PropertyName="SelectedDate" />
     </SelectParameters>
</asp:SqlDataSource>


3 Answers, 1 is accepted

Sort by
0
Andrey
Telerik team
answered on 20 Jun 2013, 12:11 PM
Hi,

You could use the DateSelecting event to check what is the date that is going to be selected and if it is the same as today you could cancel the event. You could check this online demo application for an illustration how to hook the DateSelecting event. Additionally, more information could be found in this help topic.


Regards,
Andrey
Telerik
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 the blog feed now.
0
Tom
Top achievements
Rank 1
answered on 24 Jun 2013, 08:43 PM
Is there a way to do this in code behind?  I tried using the samples you suggested but I don't know javascript and after an hour I wasn't able to make any progress.

I was thinking of setting the selected date in viewstate.  If the selected date is clicked a second time, I could grab the "previous date" from viewstate.

It seems there should be a property to disallow clicking a selected date...  I'm using web forms and vb.net.  Thanks!
0
Shinu
Top achievements
Rank 2
answered on 25 Jun 2013, 07:01 AM
Hi Tom,

Please have a look at the following code I tried which works fine at my end.

ASPX:
<telerik:RadCalendar ID="Calendar1" runat="server" AutoPostBack="true" EnableMultiSelect="false"
    ShowRowHeaders="false" Skin="MetroTouch" RenderMode="Lightweight" ClientEvents-OnDateSelecting="OnDateSelecting"
    onselectionchanged="Calendar1_SelectionChanged">
</telerik:RadCalendar>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:NorthwindConnectionString %>">
    <SelectParameters>
        <asp:ControlParameter ControlID="Calendar1" Name="calendar1" PropertyName="SelectedDate" />
    </SelectParameters>
</asp:SqlDataSource>

JavaScript:
<script type="text/javascript">
    function OnDateSelecting(sender, args) {
        if (args.get_isSelecting() == false) {
            args.set_cancel(true);
        }
    }
</script>

As far as I know, this is an optimum way to achieve your requirement. Each time you select a date from the RadCalendar the OnDateSelecting JavaScript method is called and there you can check the boolean status of the get_isSelecting() method. Using the get_isSelecting() method you can check if the date is already selected or not. Initially when you select a date from the RadCalendar the args.get_isSelecting() method will return true and the server side OnSelectionChanged event is executed where you can write the necessary code to populate the listview. Again if you select the same date from the RadCalendar, the args.get_isSelecting() method will return false and you can prevent the control from executing the OnSelectionChanged server side event using  the args.set_cancel(true). Hence the listview is not populated if the user repeatedly select the same date.

Thanks,
Shinu.
Tags
Calendar
Asked by
Tom
Top achievements
Rank 1
Answers by
Andrey
Telerik team
Tom
Top achievements
Rank 1
Shinu
Top achievements
Rank 2
Share this question
or