Telerik is a leading vendor of ASP.NET AJAX, ASP.NET MVC, Silverlight, WinForms and WPF controls and components, as well as .NET Reporting, .NET ORM , .NET CMS, Code Analysis, Mocking, Team Productivity and Automated Testing Tools. Building on its expertise in interface development and Microsoft technologies, Telerik helps customers build applications with unparalleled richness, responsiveness and interactivity. Telerik products help thousands of companies to be more productive and deliver reliable applications under budget and on time.
Version Q2 2011 released 07/12/2011
select

Calendar / DayRender Event


Server Mode Calendar

Client Mode Calendar
Selected date:


Selected day color:


Selected day text:




  • The demo illustrates how to utilize the DayRender server and client events of RadCalendar to customize the appearance of the rendered date. Note that in order to apply changes purely client-side attaching the DayRender client event, you need to navigate to a different month and thus force the calendar to re-render itself.

Source Code

C# VB.NET
Show code in new window Demo isolation steps
  • <%@ Page CodeFile="DefaultCS.aspx.cs" Language="c#" Inherits="Telerik.Web.Examples.Calendar.Programming.DayRenderEvent.DefaultCS" %>

    <%@ Register TagPrefix="telerik" Namespace="Telerik.Web.UI" Assembly="Telerik.Web.UI" %>
    <%@ Register TagPrefix="qsf" TagName="Header" Src="~/Common/Header.ascx" %>
    <%@ Register TagPrefix="qsf" TagName="HeadTag" Src="~/Common/HeadTag.ascx" %>
    <%@ Register TagPrefix="qsf" TagName="Footer" Src="~/Common/Footer.ascx" %>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <qsf:HeadTag ID="Headtag1" runat="server"></qsf:HeadTag>
    </head>
    <body class="BODY">
        <form id="mainForm" method="post" runat="server">
        <qsf:Header ID="Header1" runat="server" NavigationLanguage="CS"></qsf:Header>
        <telerik:RadScriptManager ID="RadScriptManager1" runat="server" />
        <telerik:RadCodeBlock ID="RadCodeBlock1" runat="server">
            <script type="text/javascript">
                 //<![CDATA[
                function OnDayRender(calendarInstance, args) {
                    var date = new Date(args.get_date()[0], args.get_date()[1] - 1, args.get_date()[2]);
                    var selectedDay = document.getElementById("DatesList").value;
                    var selectedDayColor = document.getElementById("ColorList").value;
                    var selectedDayText = document.getElementById("DayString").value;
                    if ((date.getDate() == selectedDay) && (date.getMonth() == (calendarInstance.get_focusedDate()[1] - 1))) {
                        args.get_cell().innerHTML = selectedDayText;
                        args.get_cell().style.backgroundColor = selectedDayColor;
                    }
                }

                function navigateCalendar() {
                    var calendar = $find("<%= RadCalendar2.ClientID %>");
                    //In order to fire the client-side OnDayRender event, the calendar should be navigated to a view different that the current one.
                    var nextMonthDay = [calendar.get_focusedDate()[0], calendar.get_focusedDate()[1] + 1, calendar.get_focusedDate()[2]];
                    calendar.navigateToDate(nextMonthDay);
                }
                     //]]>
            </script>
        </telerik:RadCodeBlock>
        <telerik:RadAjaxManager ID="RadAjaxManager1" runat="server">
            <AjaxSettings>
                <telerik:AjaxSetting AjaxControlID="Button1">
                    <UpdatedControls>
                        <telerik:AjaxUpdatedControl ControlID="RadCalendar1" LoadingPanelID="RadAjaxLoadingPanel1">
                        </telerik:AjaxUpdatedControl>
                    </UpdatedControls>
                </telerik:AjaxSetting>
                <telerik:AjaxSetting AjaxControlID="RadCalendar1">
                    <UpdatedControls>
                        <telerik:AjaxUpdatedControl ControlID="RadCalendar1" LoadingPanelID="RadAjaxLoadingPanel1">
                        </telerik:AjaxUpdatedControl>
                    </UpdatedControls>
                </telerik:AjaxSetting>
            </AjaxSettings>
        </telerik:RadAjaxManager>
        <telerik:RadAjaxLoadingPanel ID="RadAjaxLoadingPanel1" runat="server" />
        <table id="Table1" cellspacing="0" cellpadding="0" width="90%" style="margin: auto"
            border="0">
            <tr>
                <td style="width: 30%; vertical-align: top; padding-right: 5px">
                    <telerik:RadCalendar ID="RadCalendar1" runat="server" TitleFormat="MMMM yyyy" AutoPostBack="true"
                        OnDayRender="CustomizeDay">
                    </telerik:RadCalendar>
                    <br />
                    <asp:Label ID="ServerCalendarLabel" runat="server" Style="margin-bottom: 2px;">Server Mode Calendar</asp:Label>
                </td>
                <td style="width: 30%; vertical-align: top; padding-right: 15px">
                    <telerik:RadCalendar ID="RadCalendar2" runat="server" TitleFormat="MMMM yyyy" AutoPostBack="false">
                        <ClientEvents OnDayRender="OnDayRender" />
                    </telerik:RadCalendar>
                    <br />
                    <asp:Label ID="ClientCalendarMode" runat="server" Style="margin-bottom: 2px;">Client Mode Calendar</asp:Label>
                </td>
                <td style="vertical-align: top" class="module">
                    Selected date:<br />
                    <label for="DatesList">
                    </label>
                    <asp:DropDownList ID="DatesList" runat="server" Width="200px">
                        <asp:ListItem Value="1">1</asp:ListItem>
                        <asp:ListItem Value="2">2</asp:ListItem>
                        <asp:ListItem Value="3">3</asp:ListItem>
                        <asp:ListItem Value="4">4</asp:ListItem>
                        <asp:ListItem Value="5">5</asp:ListItem>
                        <asp:ListItem Value="6">6</asp:ListItem>
                        <asp:ListItem Value="7">7</asp:ListItem>
                        <asp:ListItem Value="8">8</asp:ListItem>
                        <asp:ListItem Value="9">9</asp:ListItem>
                        <asp:ListItem Value="10">10</asp:ListItem>
                        <asp:ListItem Value="11">11</asp:ListItem>
                        <asp:ListItem Value="12">12</asp:ListItem>
                        <asp:ListItem Value="13">13</asp:ListItem>
                        <asp:ListItem Value="14">14</asp:ListItem>
                        <asp:ListItem Value="15">15</asp:ListItem>
                        <asp:ListItem Value="16">16</asp:ListItem>
                        <asp:ListItem Value="17">17</asp:ListItem>
                        <asp:ListItem Value="18">18</asp:ListItem>
                        <asp:ListItem Value="19">19</asp:ListItem>
                        <asp:ListItem Value="20">20</asp:ListItem>
                        <asp:ListItem Value="21">21</asp:ListItem>
                        <asp:ListItem Value="22">22</asp:ListItem>
                        <asp:ListItem Value="23">23</asp:ListItem>
                        <asp:ListItem Value="24">24</asp:ListItem>
                        <asp:ListItem Value="25">25</asp:ListItem>
                        <asp:ListItem Value="26">26</asp:ListItem>
                        <asp:ListItem Value="27">27</asp:ListItem>
                        <asp:ListItem Value="28">28</asp:ListItem>
                        <asp:ListItem Value="29">29</asp:ListItem>
                        <asp:ListItem Value="30">30</asp:ListItem>
                        <asp:ListItem Value="31">31</asp:ListItem>
                    </asp:DropDownList>
                    <br />
                    <br />
                    Selected day color:<br />
                    <label for="ColorList">
                    </label>
                    <asp:DropDownList ID="ColorList" runat="server" Width="200px">
                        <asp:ListItem Value="White">White</asp:ListItem>
                        <asp:ListItem Value="Yellow">Yellow</asp:ListItem>
                        <asp:ListItem Value="Orange" Selected="True">Orange</asp:ListItem>
                        <asp:ListItem Value="Pink">Pink</asp:ListItem>
                        <asp:ListItem Value="Magenta">Magenta</asp:ListItem>
                        <asp:ListItem Value="Red">Red</asp:ListItem>
                        <asp:ListItem Value="Purple">Purple</asp:ListItem>
                        <asp:ListItem Value="Blue">Blue</asp:ListItem>
                        <asp:ListItem Value="Cyan">Cyan</asp:ListItem>
                        <asp:ListItem Value="Green">Green</asp:ListItem>
                        <asp:ListItem Value="Grey">Grey</asp:ListItem>
                        <asp:ListItem Value="Brown">Brown</asp:ListItem>
                    </asp:DropDownList>
                    <br />
                    <br />
                    Selected day text:<br />
                    <label for="DayString">
                    </label>
                    <asp:TextBox ID="DayString" runat="server" Width="200px">Test</asp:TextBox><br />
                    <br />
                    <table>
                        <tr>
                            <td>
    <asp:Button runat="server" ID="Button1" Width="105px" Height="60px" Font-Size="Smaller"
    Text="Apply on server" />

                            </td>
                            <td>
                                <button id="button2" onclick="navigateCalendar(); return false;" style="width: 105px;
                                    height: 60px; font-size: 11px;">
                                    Apply on client</button>
                            </td>
                        </tr>
                    </table>
                </td>
            </tr>
        </table>
        <br />
        <qsf:Footer ID="Footer1" runat="server"></qsf:Footer>
        </form>
    </body>
    </html>

Get more than expected!

 
 

Take your time to truly experience the power of RadControls for ASP.NET AJAX with a free 60-day trial backed up by Telerik’s unlimited dedicated support.

Download your RadControls for ASP.NET AJAX trial and jumpstart your development with the available Getting Started resources.

If you have any questions, do not hesitate to contact us at sales@telerik.com.

Copyright 2002-2024 © Telerik. All right reserved
Telerik Inc, 201 Jones Rd, Waltham, MA 02451