Disable selected date on RadCalendar?

4 posts, 0 answers
  1. Tom
    Tom avatar
    9 posts
    Member since:
    Aug 2012

    Posted 17 Jun 2013 Link to this post

    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 %>">
            <asp:ControlParameter ControlID="Calendar1" Name="calendar1" PropertyName="SelectedDate" />

  2. Andrey
    Andrey avatar
    836 posts

    Posted 20 Jun 2013 Link to this post


    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.

    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.
  3. Tom
    Tom avatar
    9 posts
    Member since:
    Aug 2012

    Posted 24 Jun 2013 Link to this post

    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!
  4. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 25 Jun 2013 Link to this post

    Hi Tom,

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

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

    <script type="text/javascript">
        function OnDateSelecting(sender, args) {
            if (args.get_isSelecting() == false) {

    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.

Back to Top