How to disable date deselect?

5 posts, 0 answers
  1. wajira
    wajira avatar
    7 posts
    Member since:
    Mar 2009

    Posted 26 Oct 2009 Link to this post

    I'm using RAD Calender with Multiselect = 'False'.
    When I click on an already selected date, the date get deselected.
    I want to stop that.

    Is there any property to do that or How Can I do that?
  2. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 26 Oct 2009 Link to this post

    Hi,

    Attach OnDateSelecting event to RadCalendar and try the following client side code.

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

    -Shinu.
  3. wajira
    wajira avatar
    7 posts
    Member since:
    Mar 2009

    Posted 27 Oct 2009 Link to this post

    Hi Shinu ,

    It looks It works.
    Thanx.
  4. Samuel
    Samuel avatar
    24 posts
    Member since:
    Feb 2009

    Posted 07 Feb 2011 Link to this post

    Does this solution still work?
    When I try this script, it breaks the EnableMultiSelect="False"
    In other words, multiple days can be selected despite multiselect being turned off.

    I am using 2010.03.1109.40
  5. Marin
    Admin
    Marin avatar
    1057 posts

    Posted 10 Feb 2011 Link to this post

    Hi Samuel,

    You can use the OnDateClick event to get the date that is about to be selected and then compare it with the current date. Here is a code sample:

    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;
            }

    Best wishes,
    Marin
    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