Hello,
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: http://www.telerik.com/community/forums/thread/b311D-bgmttm.aspx
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.
-Drew
C#
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);
currentCell.Controls.Add(button);
}
}
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)
{
}
}
Asp.Net
<%@ 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>
</telerik:RadCalendar>
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: http://www.telerik.com/community/forums/thread/b311D-bgmttm.aspx
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.
-Drew
C#
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);
currentCell.Controls.Add(button);
}
}
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)
{
}
}
Asp.Net
<%@ 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>
</telerik:RadCalendar>