CustomCalendar.cs problem - ch. 13
Hey all,
I'm having a problem with the custom calendar ... once I switch from the original calendar to the custom one, no calendar displays! This happens when I use the code included in the complete code download as well. I'm using the C# version of the book.
Any help would be appreciated--Code follows.
// CustomCalendar.cs
//
namespace WroxUnited
{
using System;
using System.ComponentModel;
using System.Web.UI;
using System.Collections;
using System.Web.UI.WebControls;
public class CustomCalendar : Control, INamingContainer
{
private Calendar calendar;
public event EventHandler SelectionChanged;
private Hashtable _dateList;
public Hashtable DateList
{
get
{
return _dateList;
}
set
{
_dateList = value;
}
}
public DateTime SelectedDate
{
get
{
return calendar.SelectedDate;
}
}
protected override void CreateChildControls()
{
calendar.CssClass = "calendar";
calendar.DayStyle.CssClass = "normaldate";
calendar.OtherMonthDayStyle.CssClass = "othermonthdate";
this.Controls.Add(calendar);
}
protected override void OnInit(EventArgs e)
{
base.OnInit(e);
calendar = new Calendar();
calendar.DayRender += new DayRenderEventHandler(this.EventCalendar_DayRender );
calendar.SelectionChanged += new EventHandler(this.EventCalendar_SelectionChanged);
}
private void EventCalendar_DayRender(object sender, DayRenderEventArgs e)
{
if (_dateList != null)
{
if (_dateList[e.Day.Date] != null)
{
e.Cell.CssClass = "selecteddate";
e.Day.IsSelectable = true;
}
else
{
e.Day.IsSelectable = false;
}
}
else
{
e.Day.IsSelectable = false;
}
}
private void EventCalendar_SelectionChanged(object sender, EventArgs e)
{
if (SelectionChanged != null)
{
SelectionChanged(this, e);
}
}
}
}
// From Default.aspx
<%@ Register TagPrefix="WroxUnitedCalendar" Namespace="WroxUnited" Assembly="CustomCalendar" %>
.
.
.
<html>
.
.
.
<form>
.
.
.
<WROXUNITEDCALENDAR:CUSTOMCALENDAR id="EventCalendar" runat="server" OnSelectionChanged="EventCalendar_SelectionChanged " />
// From Default.aspx.cs
.
.
.
public WroxUnited.CustomCalendar EventCalendar;
.
.
.
public void Page_Load(object sender, EventArgs e)
{
.
.
.
EventCalendar.DateList = (Hashtable)Cache["DateList"];
.
.
.
}
|