I am using the Online Demo Calendar Template example http://demos.telerik.com/aspnet-ajax/calendar/examples/functionality/specialdays/defaultcs.aspx to create a templated calendar. I want to assign all Saturday/Sundays and all days prior to todays date to a template to indicate these days are unavailable. I also want to assign days pulled from a database to this template as well (I have not implemented the database piece yet, my code below is just assigning today's date).
I created the template declaratively like in the example. I need to assign the special days/template programmatically. I am using the RadCalendar_DayRender event to assign special days/template for the saturday/sunday. I am using the Page_Load event to assign the days from the database.
Days assigned in the DayRender event are not showing the template at all.
Days assigned in the Page_Load event are showing a generic template (not the template I assign) on initial page load, but then show the template that I assigned on post back.
1) How do I get the correct template to show on initial page load?
2) How can I assign all saturday/sundays and all days prior to today in the Page_Load event? or how can I get the template assignment to work in the DayRender Event.
Here is my code.
<%@ Page Title="" Language="C#" MasterPageFile="~/BlankMasterPage.master" AutoEventWireup="true" CodeFile="DatePicker.aspx.cs" Inherits="admissions_cfad_DatePicker" %>
<
asp:Content
ID
=
"Content1"
ContentPlaceHolderID
=
"head"
Runat
=
"Server"
>
<
link
href
=
"Common/Calendar.Special.css"
rel
=
"Stylesheet"
type
=
"text/css"
/>
</
asp:Content
>
<
asp:Content
ID
=
"Content2"
ContentPlaceHolderID
=
"ContentPlaceHolderTitle"
Runat
=
"Server"
>
</
asp:Content
>
<
asp:Content
ID
=
"Content3"
ContentPlaceHolderID
=
"ContentPlaceHolderMain"
Runat
=
"Server"
>
<
telerik:RadCalendar
ID
=
"RadCalendar1"
runat
=
"server"
AutoPostBack
=
"true"
skin
=
"Special"
EnableEmbeddedSkins
=
"false"
EnableEmbeddedBaseStylesheet
=
"false"
EnableMonthYearFastNavigation
=
"false"
ShowOtherMonthsDays
=
"false"
DayNameFormat
=
"Short"
EnableMultiSelect
=
"false"
OnDefaultViewChanged
=
"RadCalendar1_DefaultViewChanged"
ondayrender
=
"RadCalendar1_DayRender"
>
<
HeaderTemplate
>
<
asp:Image
ID
=
"HeaderImage"
runat
=
"server"
Width
=
"757"
Height
=
"94"
Style
=
"display: block"
/>
</
HeaderTemplate
>
<
FooterTemplate
>
<
asp:Image
ID
=
"FooterImage"
runat
=
"server"
Width
=
"757"
Height
=
"70"
Style
=
"display: block"
/>
</
FooterTemplate
>
<
CalendarDayTemplates
>
<
telerik:DayTemplate
ID
=
"NotAvailableTemplate"
runat
=
"server"
>
<
Content
>
<
div
class
=
"rcTemplate rcDayNotAvailable"
>
Not Available
</
div
>
</
Content
>
</
telerik:DayTemplate
>
</
CalendarDayTemplates
>
</
telerik:RadCalendar
>
</
asp:Content
>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Telerik.Web.UI;
public partial class admissions_cfad_DatePicker : System.Web.UI.Page
{
Image _headerImage = null;
Image _footerImage = null;
protected void Page_Load(object sender, EventArgs e)
{
_headerImage = (Image)RadCalendar1.FindControl("HeaderImage");
_footerImage = (Image)RadCalendar1.FindControl("FooterImage");
AddImages(RadCalendar1.CalendarView);
if (!Page.IsPostBack)
{
RadCalendarDay calendarDay = new RadCalendarDay();
calendarDay.Date = DateTime.Now.Date;
calendarDay.TemplateID = "NotAvailableTemplate";
calendarDay.IsSelectable = false;
RadCalendar1.SpecialDays.Add(calendarDay);
}
}
protected void RadCalendar1_DefaultViewChanged(object sender, Telerik.Web.UI.Calendar.DefaultViewChangedEventArgs e)
{
AddImages(e.NewView);
}
protected void RadCalendar1_DayRender(object sender, Telerik.Web.UI.Calendar.DayRenderEventArgs e)
{
if (e.Day.Date.DayOfWeek == DayOfWeek.Saturday || e.Day.Date.DayOfWeek == DayOfWeek.Sunday
|| e.Day.Date < DateTime.Now.Date)
{
RadCalendarDay calendarDay = new RadCalendarDay();
calendarDay.Date = e.Day.Date;
calendarDay.TemplateID = "NotAvailableTemplate";
calendarDay.IsSelectable = false;
RadCalendar1.SpecialDays.Add(calendarDay);
}
}
private void AddImages(Telerik.Web.UI.Calendar.View.CalendarView inputView)
{
switch (inputView.ViewStartDate.Month)
{
case 0:
case 1:
case 11:
_headerImage.ImageUrl = "Common/header_winter.jpg";
_footerImage.ImageUrl = "Common/footer_winter.jpg";
_headerImage.AlternateText = _footerImage.AlternateText = "Winter";
break;
case 2:
case 3:
case 4:
_headerImage.ImageUrl = "Common/header_spring.jpg";
_footerImage.ImageUrl = "Common/footer_spring.jpg";
_headerImage.AlternateText = _footerImage.AlternateText = "Spring";
break;
case 5:
case 6:
case 7:
_headerImage.ImageUrl = "Common/header_summer.jpg";
_footerImage.ImageUrl = "Common/footer_summer.jpg";
_headerImage.AlternateText = _footerImage.AlternateText = "Summer";
break;
case 8:
case 9:
case 10:
_headerImage.ImageUrl = "Common/header_autumn.jpg";
_footerImage.ImageUrl = "Common/footer_autumn.jpg";
_headerImage.AlternateText = _footerImage.AlternateText = "Autumn";
break;
}
}
}
Thank you for your help.