Preventing "unselect"

2 posts, 0 answers
  1. Loren
    Loren avatar
    7 posts
    Member since:
    Jul 2007

    Posted 08 Jan 2009 Link to this post

    I have a RadCalendar control, and I have a DataList control whose ObjectDataSource is bound to the SelectedDate property of the calendar control.  Selecting a date on the calendar populates the DataList with data for that day.  The problem I'm running into is if you click the day that's already selected, the calendar apparently unselects that day, and an invalid DateTime is passed to the ObjectDataSource  (DateTime.MinValue).  I want to prevent this from happening by disabling the unselecting of the current day, but I can't seem to find a way to do it.  I have explored canceling the event in the OnDateSelecting client event if args.IsSelecting == false, but that also cancels valid attempts to change the date as well, since it first tries to unselect the current day before selecting the new one.  How can I prevent the user from unselecting the date?

    For reference, here's my code:

    <telerik:RadCalendar   
        ID="RadCalendar1"   
        runat="server" 
        EnableMultiSelect="false"   
        AutoPostBack="true"   
        ShowRowHeaders="false"    
        UseColumnHeadersAsSelectors="false">  
        <ClientEvents OnDateSelected="OnDateSelected" /> 
    </telerik:RadCalendar> 
     
    <script type="text/javascript">  
        function OnDateSelected(sender, eventArgs) {  
            sender.set_autoPostBack(true);  
        }   
    </script> 

    In my codebehind, I'm setting the calendar's AutoPostBack property to false on PageLoad, and then setting it to true in the OnDateSelected client event.  This allows me to change months on the client side, and only post back when a date is selected.  I don't  know if it has any effect on the current situation, but I thought I'd point it out.

  2. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 09 Jan 2009 Link to this post

    Hello Loren,

    You can cancel the unselect event of a calendar if the date is already selected using the following code:
    aspx:
    <telerik:RadCalendar    
        ID="RadCalendar1"    
        runat="server"  
        EnableMultiSelect="false"    
        AutoPostBack="true"    
        ShowRowHeaders="false"     
        UseColumnHeadersAsSelectors="false">   
        <ClientEvents OnDateSelected="OnDateSelected" OnDateClick="DateClick" />  
    </telerik:RadCalendar>  

    js:
    function DateClick(sender, args)  
     {  
      if(args.get_renderDay().IsSelected)  
         args.set_cancel(true);  
     }   

    Thanks
    Princy.

Back to Top