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

5 posts, 0 answers
  1. SteveV
    SteveV avatar
    8 posts
    Member since:
    Nov 2011

    Posted 13 Jan 2012 Link to this post

    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

  2. Vasil
    Admin
    Vasil avatar
    1547 posts

    Posted 18 Jan 2012 Link to this post

    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
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. SteveV
    SteveV avatar
    8 posts
    Member since:
    Nov 2011

    Posted 19 Jan 2012 Link to this post

    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
  5. Vasil
    Admin
    Vasil avatar
    1547 posts

    Posted 20 Jan 2012 Link to this post

    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
  6. Mahendra
    Mahendra avatar
    4 posts
    Member since:
    Sep 2010

    Posted 10 Aug 2013 Link to this post


    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
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017