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

RadCalendar: Button events within cell are not firing.

1 Answer 110 Views
This is a migrated thread and some comments may be shown as answers.
Top achievements
Rank 1
Grant asked on 22 Oct 2008, 04:11 PM

My original post for this question was in the RadnControls for ASP.NET forums, but it wasn't getting responses so I have decided to paste it here.  I am using the ASP.NET Ajax version of the calendar.  Please view the following thread to other correspondence to this issue:

In the example below I am adding a button to every cell of the calendar using the OnDayRender event.  The problem I am having is that the button click event is not being fired when the button is clicked.  Instead, the OnSelectionChanged event of the RadCalendar is being fired.  Is it possible to add asp controls to the RadCalendar cells and catch their click events?  I attempted to use the code formatter, but it was flaking out so I just pasted the code below.  Thank you in advance for any replies.



using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using Telerik.RadComboboxUtils;

public partial class UserControls_EventCalendar : System.Web.UI.UserControl
    protected void Page_Load(object sender, EventArgs e)

    protected void CustomizeDay(object sender, Telerik.Web.UI.Calendar.DayRenderEventArgs e)
        DateTime CurrentDate = e.Day.Date;

        if (e.Day.Date <= e.View.MonthEndDate && e.Day.Date >= e.View.MonthStartDate)
            TableCell currentCell = e.Cell;

            currentCell.Style["background-color"] = "Orange";
            currentCell.Text = e.Day.Date.Day.ToString();
            currentCell.ID = e.Day.Date.ToString();
            Button button = new Button();
            button.Command += new CommandEventHandler(button_Command);
            button.UseSubmitBehavior = true;
            button.CausesValidation = false;
            button.ID = e.Day.Date.ToString();
            button.Text = e.Day.Date.Day.ToString();
            button.CommandName = "DatePicked";
            button.Click += new EventHandler(button_Click);



    void button_Click(object sender, EventArgs e)
        throw new NotImplementedException();

    public void button_Command(object sender, CommandEventArgs e)
        throw new NotImplementedException();

    public void OnDateClicked(object sender, Telerik.Web.UI.Calendar.SelectedDateChangedEventArgs e)

    protected void SelectedDateChange(object sender, Telerik.Web.UI.Calendar.SelectedDatesEventArgs e)

<%@ Control Language="C#" AutoEventWireup="true" CodeFile="EventCalendar.ascx.cs" Inherits="UserControls_EventCalendar" %>
<%@ Register TagPrefix="telerik" Namespace="Telerik.Web.UI" Assembly="Telerik.Web.UI" %>

<telerik:RadCalendar ID="RadCalendar1" runat="server" Width="755px" TitleFormat="MMMM yyyy"
            AutoPostBack="true" ShowRowHeaders="False" UseRowHeadersAsSelectors="False" ShowOtherMonthsDays="False"
            EnableEmbeddedSkins="false" Skin="Business" CultureInfo="English (United States)" OnDayRender="CustomizeDay" OnSelectionChanged="SelectedDateChange" >
                <WeekendDayStyle BorderWidth="1px" BorderColor="MidnightBlue"></WeekendDayStyle>
                <SelectedDayStyle BackColor="Orange"></SelectedDayStyle>
                <FastNavigationStyle BorderWidth="1px" BorderColor="MidnightBlue" BackColor="Lavender"></FastNavigationStyle>
                <DayOverStyle Font-Bold="True" ForeColor="#C0FFFF" BackColor="SlateGray"></DayOverStyle>
                <OutOfRangeDayStyle BorderWidth="1px" BorderColor="MintCream"></OutOfRangeDayStyle>
                <HeaderStyle BorderWidth="1px" BorderColor="#000040"></HeaderStyle>
                <DayStyle BorderWidth="1px" BorderColor="MidnightBlue" Height="60px"></DayStyle>
                <CalendarTableStyle BackColor="Lavender"></CalendarTableStyle>
                <OtherMonthDayStyle BorderWidth="1px" BorderColor="Navy"></OtherMonthDayStyle>

1 Answer, 1 is accepted

Sort by
Missing User
answered on 23 Oct 2008, 08:51 AM
Hi Grant,

Because the DayRender event is raised while the RadCalendar control is being rendered, you cannot add a control that can also raise an event, such as LinkButton. You can only add static controls, such as System.Web.UI..::.LiteralControl, Label, Image, and HyperLink.

All the best,
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
Asked by
Top achievements
Rank 1
Answers by
Missing User
Share this question