I am currently working on a C# web application that includes an asp:Calendar:
<asp:Calendar ID="cal_ReserveDate" runat="server"
DayStyle-ForeColor="DarkBlue" DayHeaderStyle-BackColor="#FEF6CB" DayStyle-Height="25" DayStyle-Font-Bold="true"
SelectedDayStyle-BackColor="#003F7D" SelectedDayStyle-ForeColor="White"
DayNameFormat="FirstLetter" ShowGridLines="true" BorderColor="Black"
TitleStyle-BackColor="#003F7D" TitleStyle-ForeColor="White" TitleStyle-CssClass="CalHeader"
NextPrevStyle-CssClass="CalNextPrev" NextPrevStyle-ForeColor="White"
OnVisibleMonthChanged="cal_ReserveDate_VisibleMonthChanged"
OnDayRender="cal_ReserveDate_DayRender" OnSelectionChanged="cal_ReserveDate_SelectionChanged"
DayStyle-BorderColor="Black" SelectedDayStyle-CssClass="CalendarSelectedDay" Width="97%" Font-Bold="true" />
My goal is to customize specific date colors using the OnDayRender
function, such as for closed or sold out dates. I also want to allow our design team to set today's color through the stylesheet. To start, I added this CSS style:
.calendarToday {
background-color: mistyrose;
}
In my rendering code for "today," I have the following:
if (e.Day.IsToday)
{
string onmouseoutStyle = "this.style.backgroundColor='@BackColor'";
e.Cell.CssClass = "calendarToday";
e.Cell.Attributes.Add("onmouseout", onmouseoutStyle.Replace("@BackColor", <<read current bgColor>>));
}
This logic resembles what I use for marking sold-out days and resetting background colors upon mouse-out, but in other instances, I have fixed predefined colors hardcoded in the app. My challenge now is figuring out how to access the e.Cell
attributes, particularly the background-color
, to determine the color set by designers in the calendarToday
style sheet.
If anyone can provide insight into accessing this information, it would be greatly appreciated! Thank you for your attention - Jim