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

RadCalendar calling CalendarView.ViewStartDate or ViewEndDate from Init event breaks navigation

4 Answers 128 Views
Calendar
This is a migrated thread and some comments may be shown as answers.
SteveV
Top achievements
Rank 1
SteveV asked on 13 Jan 2012, 11:54 PM
I'm working on a custom calendar control that contains a RadCalendar.  The control is being used to display a monthly school calendar that shows in-session days, holidays, vacation days, etc.  I need to be able to add these items dynamically from codebehind so I can add text and color code the items, etc.  I'm using the ITemplate interface to add CalendarDayTemplates as described in this post.  

Unfortunately, I've run into what appears to be a bug.  Accessing the calendar's CalendarView.ViewStartDate or CalendarView.ViewEndDate properties from the calendar's Init event completely breaks calendar navigation.  I have tried adding the  CalendarDayTemplates in the calendar's Prerender event but it appears that this is too late in the control's lifecyle as I get the following exception:

Server Error in '/' Application.

Template with ID: 02202012 not found.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Exception: Template with ID: 02202012 not found.

If have confirmed that the issue is not with my code by stripping out everything but code that accesses CalendarView.ViewStartDate or CalendarView.ViewEndDate properties.

Here's how to reproduce the problem:

aspx code:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="default2.aspx.cs" Inherits="NLGOnLineTestClient.default2" %>
 
<%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %>
 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
 
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:ScriptManager ID="ScriptManager1" runat="server" />
        <telerik:RadCalendar ID="RadCalendar1" runat="server" AutoPostBack="True" oninit="RadCalendar1_Init">
        </telerik:RadCalendar>
            </div>
    </form>
</body>
</html>



codebehind:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
 
namespace NLGOnLineTestClient
{
    public partial class default2 : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
        }
 
        protected void RadCalendar1_Init(object sender, EventArgs e)
        {
            string range = string.Format("Start: {0}  End {1}", RadCalendar1.CalendarView.ViewStartDate.ToString("g"), RadCalendar1.CalendarView.ViewEndDate.ToString("g"));
            System.Diagnostics.Debug.WriteLine(range);
        }
    }
}


When running this, note that you can only move one month forward and one month back from the current month.  Attempting to navigate additional months has no effect.  Looking at FireBug's script tag show no errors.

The very bad news is that I was close to 2 days into working on getting this working and styled when I discovered this problem.  Any suggestions or word arounds would be VERY appreciated.

Thanks -- Steve

4 Answers, 1 is accepted

Sort by
0
Vasil
Telerik team
answered on 18 Jan 2012, 05:21 PM
Hi Steve,

The problem happens because on Init event the CalendarView is still not recreated from the ViewState.
And when you try to access it the calendar get's new CalendarView that Initialize with the given.
The solution as described in the other forum thread that you have quoted already is to access this view later in the control life-cycle, after it's ViewState is loaded properly.
Please note that the Init event of the page is later than the Init event of the control. So try to do your logic on Page_Init or Page_Load.

Regards,
Vasil
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now
0
SteveV
Top achievements
Rank 1
answered on 19 Jan 2012, 01:10 PM
Hi Vasil,

The control is being used on a dynamically created page so adding controls to the calendar in the page's init event adds some complications.  I spent several hour redesigning the control and am able to most of what I need to in the DayRender event.

Thanks -- Steve
0
Vasil
Telerik team
answered on 20 Jan 2012, 09:25 AM
Hi Steve,

I am glad that you have redesigning the control and solved the issue.
As an addiction I would say that you could use the RadCalendar's OnLoad event and it should work correct.

Greetings,
Vasil
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now
0
Mahendra
Top achievements
Rank 1
answered on 10 Aug 2013, 06:47 AM

Hi all,

Me too had the same issue when i navigate through months.

What i did is calling the clear method for Special Days of the calendar as we are changing the months.

So by clearing the Special Days and CalendarDayTemplate resolved the issue.

Hope it helps.

Regards,
Mahendra
Tags
Calendar
Asked by
SteveV
Top achievements
Rank 1
Answers by
Vasil
Telerik team
SteveV
Top achievements
Rank 1
Mahendra
Top achievements
Rank 1
Share this question
or