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

rad datepicker and highlighting Sat and Sunday different colors

1 Answer 318 Views
Calendar
This is a migrated thread and some comments may be shown as answers.
Tim
Top achievements
Rank 1
Tim asked on 18 Nov 2010, 09:14 PM
I am designing a date time control using the raddatepicker.  I want Sundays to be highlighted a different color than saturday, we are open on saturdays and closed on sundays.  so mondays thru saturday (excluding holidays or special days) should be the same back ground color.

I've tried both the client and server side (OnDayRender) to control this but its too inconsistent.

What can i do differently?  Attached is the vb and javascript i am using.

Tim Martin
Car Research
             <script type="text/javascript">
                 function OnDayRender(calendarInstance, args) {
6) and Sunday (day = 0))
                                        
                     var jsDate = new Date(args.get_date()[0], args.get_date()[1] - 1, args.get_date()[2]);
                     if (jsDate.getDay() == 0) {
                         var otherMonthCssClass = "CalendarDisabled";
                         args.get_cell().className = otherMonthCssClass;
 
                         args.get_cell().innerHTML = "<span>" + args.get_date()[2] + "</span>";
 
 
                         args.get_cell().DayId = "";
                     } else {
                         var otherMonthCssClass = "CalendarEnabled";
                         args.get_cell().className = otherMonthCssClass;
 
                         args.get_cell().innerHTML = "<span>" + args.get_date()[2] + "</span>";
                     }
                 }
            </script>


Protected Sub Calendar_OnDayRender(ByVal sender As Object, ByVal e As Telerik.Web.UI.Calendar.DayRenderEventArgs)
    Dim specialday As New RadCalendarDay
 
    If e.Day.Date.DayOfWeek = DayOfWeek.Sunday Then
        specialday.Date = e.Day.Date
        specialday.IsSelectable = False
        specialday.ToolTip = "Closed"
        specialday.ItemStyle.CssClass = "CalendarDisabled"
        With rdpDatePicker
            .Calendar.SpecialDays.Add(specialday)
        End With
    ElseIf e.Day.Date.DayOfWeek = DayOfWeek.Saturday Then
        specialday.Date = e.Day.Date
        specialday.IsSelectable = True
        specialday.ItemStyle.CssClass = "CalendarEnabled"
        With rdpDatePicker
            .Calendar.SpecialDays.Add(specialday)
        End With
 
    End If
End Sub

1 Answer, 1 is accepted

Sort by
0
Tsvetina
Telerik team
answered on 24 Nov 2010, 10:50 AM
Hello Tim,

Here is a more stripped down approach that you can try which handles the desired functionality without the need of special days. Generally it sets the colors of the current view in code-behind and the colors after navigating on the client:
<telerik:RadDatePicker ID="rdpDatePicker" runat="server" >
    <Calendar runat="server" ClientEvents-OnDayRender="dayRender" OnDayRender="Calendar_OnDayRender" />
</telerik:RadDatePicker>

VB:
Protected Sub Calendar_OnDayRender(ByVal sender As Object, ByVal e As Telerik.Web.UI.Calendar.DayRenderEventArgs)
 If e.Day.Date.DayOfWeek = DayOfWeek.Sunday Then
            e.Cell.Style("background-color") = "#33ccff"
        End If
End Sub

javascript:
function dayRender(sender, eventArgs) {
    var jsDate = new Date(eventArgs.get_date()[0], eventArgs.get_date()[1] - 1, eventArgs.get_date()[2]);
    if (jsDate.getDay() == 0) {
        eventArgs.get_cell().style.backgroundColor = "#33ccff";
    }
}


Greetings,
Tsvetina
the Telerik team
Browse the vast support resources we have to jumpstart 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.
Tags
Calendar
Asked by
Tim
Top achievements
Rank 1
Answers by
Tsvetina
Telerik team
Share this question
or