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

ClientEvents-OnDateClick get background color on the date clicked

1 Answer 194 Views
Calendar
This is a migrated thread and some comments may be shown as answers.
Martin
Top achievements
Rank 1
Martin asked on 11 Feb 2009, 12:51 PM
I have a small web project where im using a radcalendar.

The calendar is used to show different states shown as with different background colors. In the codebehind DayRender event i set up the Background color setting the Cell CssClass for each day...

now its possible for the user to change the state on a date by clicking it. Here is the question. ? If a date has a specific color "lets say green" and the user clicks it i want to show a confirm messagebox. How do i get the clicked dates backgroundcolor in the ClientEvent.

my aspx looks like below:

 

<telerik:RadCalendar ID="uiCalendarPersonal" runat="server" AutoPostBack="True" width="170px"  
    ClientEvents-OnDateClick="OnDateClick" 
    OnDayRender="uiCalendarPersonal_DayRender">
</telerik:RadCalendar>

The javascript for OnDateClick will look something like this

function OnDateClick(calendarInstance, args) { 
   //set set_Cancel(true) to cancel AutoPostBackOnDayClick - if any;
    // here i would like to check for the clicked dates backgroundcolor
    args.set_cancel(!TraceEvent(
"OnDateClick: " + args.get_renderDay().get_date(), "Postback?")); 


function TraceEvent(eventName, confirmMessage) { 
   var now = new Date(); 
   var str = "[" + now.toLocaleTimeString() + "]&nbsp;" + eventName; 
   var retValue; 
   if (confirmMessage) { 
       retValue = confirm(eventName +
":\n" + confirmMessage); 
       str += (retValue ?
"" : "&nbsp;-&nbsp;canceled"); 
       }
   if (retValue != null
       return retValue;
}

 

 

 

 

 

 

 

1 Answer, 1 is accepted

Sort by
0
Daniel
Telerik team
answered on 16 Feb 2009, 03:49 PM
Hello Martin,

Sample approach is shown below:
<script type="text/javascript" language="javascript"
    function getStyle(x, styleProp) 
    { 
        if (x.currentStyle) 
            var y = x.currentStyle[styleProp]; 
        else if (window.getComputedStyle) 
            var y = document.defaultView.getComputedStyle(x, null).getPropertyValue(styleProp); 
        return y; 
    } 
 
    function OnDateClick(sender, args) 
    { 
        alert(getStyle(args.get_domEvent().target.parentNode, "backgroundColor")); 
    } 
</script> 


Regards,
Daniel
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
Tags
Calendar
Asked by
Martin
Top achievements
Rank 1
Answers by
Daniel
Telerik team
Share this question
or