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

Preventing "unselect"

1 Answer 151 Views
Calendar
This is a migrated thread and some comments may be shown as answers.
Loren
Top achievements
Rank 1
Loren asked on 08 Jan 2009, 11:12 PM
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.

1 Answer, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 09 Jan 2009, 11:46 AM
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.

Tags
Calendar
Asked by
Loren
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Share this question
or