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

CalendarDay Template Problem

5 Answers 107 Views
Calendar
This is a migrated thread and some comments may be shown as answers.
Jeff Clark
Top achievements
Rank 1
Jeff Clark asked on 14 Sep 2010, 07:46 PM

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.

5 Answers, 1 is accepted

Sort by
0
Iana Tsolova
Telerik team
answered on 15 Sep 2010, 12:32 PM
Hello Jeff,

When adding special days to the RadCalendar dynamically, you should do it on Page_Load. The DayRender event is fired too late for the day changes to be applied.
Furthermore, if you want to disable the weekend days prior today, you can check out the solution provided in this code library. Otherwise you will need to add them as SpecialDays on Page_Load againg, by traversing all weekend date from the RangeMinDate upto today.

Best wishes,
Iana
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Jeff Clark
Top achievements
Rank 1
answered on 15 Sep 2010, 01:50 PM
Hi Lana,

Thanks for the response.  That sort of answers my second question. The code sample is for a RadDatePicker. I will try to adapt it to the RadCalendar.

What I am most interested in though is my first question.  For the special days that are assigned in the Page_Load event, the templates do not show on the initial page load. They do show on post backs.  How do I get the template to show on the initial page load?

Thanks for your help.
0
Iana Tsolova
Telerik team
answered on 16 Sep 2010, 12:11 PM
Hello Jeff,

I tested the day templates applying on my side but was not able to replicate it. Can you check the attached sample and let me know what differs in your case?

Best wishes,
Iana
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Jeff Clark
Top achievements
Rank 1
answered on 16 Sep 2010, 03:04 PM
Hi Lana,

The difference in my case is that I am using a custom skin. I am using the custom skin from the online example. I tested your sample and it works, but when I add the custom skin to your sample it does not work.

I need this to work with a custom skin. I am submitting a support ticket, so that I can submit a sample to demonstrate the issue.

Thanks for your help.
0
Iana Tsolova
Telerik team
answered on 16 Sep 2010, 03:27 PM
Hello Jeff,

Thank you for opening a formal support ticket. I will perform further testing on the provided there and turn back to you with a resolution.

Sincerely yours,
Iana
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Tags
Calendar
Asked by
Jeff Clark
Top achievements
Rank 1
Answers by
Iana Tsolova
Telerik team
Jeff Clark
Top achievements
Rank 1
Share this question
or