AJAX and Calendar Issues

2 posts, 0 answers
  1. Andrew Bornand
    Andrew Bornand avatar
    4 posts
    Member since:
    Dec 2006

    Posted 13 May 2009 Link to this post

    Hello, I am trying to disable certain days (Sundays and Mondays) in my calendar pop-up based on a dropdown value.

    This Calendar is part of a RateDatePicker.

    My code is as follows: (for Brevity I am just enclosing the snippet for Sundays)

    <telerik:RadDatePicker runat="server" ID="rdpDate" OnSelectedDateChanged="rdpDate_Changed" AutoPostBack="true" Calendar-ShowRowHeaders="false" Calendar-ShowColumnHeaders="false">
                                        <Calendar ID="Calendar1" OnDayRender="cal_DayRender" runat="server">
                                            <CalendarDayTemplates>
                                                <telerik:DayTemplate ID="OtherMonth" runat="server">
                                                    <Content>
                                                        X
                                                    </Content>
                                                </telerik:DayTemplate>
                                            </CalendarDayTemplates>
                                        </Calendar>
                                        </telerik:RadDatePicker>



    protected void cal_DayRender(object sender, Telerik.Web.UI.Calendar.DayRenderEventArgs e)
        {
            if (e.Day.Date.DayOfWeek == DayOfWeek.Sunday)
            {
                switch (ddlChoices.SelectedValue)
                {
                    case "choice1":
                    case "choice2":
                    case "choice3":
                        //e.Day.IsSelectable = false;
                        

                        e.Cell.Controls.Clear();
                        e.Cell.CssClass = "otherMonth";

                        Label label = new Label();
                        label.Text = e.Day.Date.Day.ToString();
                        e.Cell.Controls.Add(label);

                        Telerik.Web.UI.RadCalendarDay calendarDay = new Telerik.Web.UI.RadCalendarDay();
                        calendarDay.Date = e.Day.Date;
                        calendarDay.IsSelectable = false;
                        calendarDay.IsDisabled = true;
                        calendarDay.TemplateID = "OtherMonth";
                        rdpDate.Calendar.SpecialDays.Add(calendarDay);
                        break;
                }
            }
    }

    The effect that occurs is that there's no longer an <a> tag in the span for that day but the over/off javascript that changes the CSS class events are firing and I can still click in the box for the day and it will populate the textbox.  The effect I want is for the dates that I disable to be completly unclickable.  Any suggestions on dealing with the dropdown?

    Is there a way for me to "reload" the viewed month?  I thought I might reload the calendar in the postback _Changed event handler for the dropdown list. I only plan on showing a year's worth of dates, would it be possible for me to create an IList<DateTime> and DataBind the calender that way and not have to deal with a javascript handler for new months?  I could deal with both problems at once.

    If the "SpecialDays" functionality is not needed that's fine, all I need is to disable the dates.  Thanks!

    I removed the AJAX manager and now it seems to be working.  Is there a trick to getting this to work with RadAjaxManager?  Thanks.

    I'm using a sequence of Panels to control the flow of my page and the ajax affects some of these.  When the flow returns back to the panel with the calendar in it sometimes the calendar control has all of it's styles removed and it looks very plain with no skin on the calendar.  If I take out the AJAX manager this works.  Am I missing something important with the AJAX manager?

    Thanks.
  2. Iana Tsolova
    Admin
    Iana Tsolova avatar
    3388 posts

    Posted 14 May 2009 Link to this post

    Hello Andrew,

    Unfortunately when RadCalendar is ajaxified with RadAjaxManager, calendar changes made in the DayRender server event are not applied after ajax request.
    Please try replacing the ajax manager with ASP:UpdatePanel.

    Greetings,
    Iana
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
Back to Top