Calendar Control: Selected Day Formatting Problem

G

Gilles Muys

For an unknown reason, my calendar control automatically adds a style
attribute to the cell of the selected day. This style attribute is:

style="color:White;background-color:Silver;width:14%;"

In my DayRender event handler, I set the CssClass of the cell of the
selected day to "DaySelected". This CssClass has completely different colors
than the style attribute mentionned above. The rendered output is the
following:

<td class="DaySelected" align="Center"
style="color:White;background-color:Silver;width:14%;">

So the CssClass is properly changed, but the style attribute overrides its
settings. I have added SelectedDayStyle-CssClass="DaySelected" in the ASPX
code, but this did not help.

Since I have not requested this style attribute to be added in any manner, I
assume that the Calendar control itself is doing this. How can I prevent
this from happening?

TIA

Gilles
 
J

Jason

I believe this is a bug that probably came about from the original Calendar
control author not using external style sheets. Basically, the default
styles of all the calendar parts are output inline. If you specify them
programmatically or declare them, then they get updated normally. If you
don't, then it renders the defaults (whether you like it or not). Since
inline styles override styles declared in the <head> or linked to an
external style sheet there is no good way to accomplish css. There is a
Color.Empty that had me going about a year ago, but it turns out that that
just renders black.

As a work around you can declare the styles that show up by default as
!important

For instance, background-color is always set to Silver in the SelectedDay
inline style. well in this example it still is inline as Silver but it will
actually show as green since the !imporatant overrides the inline style:

<head>
<style>
.Bob
{
font: 20pt times;
background-color: green !important;
}
</style>
</head>
<body>
<asp:Calendar id="Calendar1" runat="server">
<SelectedDayStyle CssClass="Bob" ></SelectedDayStyle>
</asp:Calendar>
</body>

having to use !imporatant to get styles to work with css, IMO, makes the
calendar a broken control. you could use grow your own css compliant
version of course or try to find a good one to purchase. If you are not a
stickler for CSS you could do this all manually by setting the
background-color programmatically, but it defeats the purpose of css
altogether at that point.

Maybe somebody else has figured out how to work around this problem.
 
G

Gilles Muys

Thanks Jason! It worked wonderfully.

Gilles

Jason said:
I believe this is a bug that probably came about from the original Calendar
control author not using external style sheets. Basically, the default
styles of all the calendar parts are output inline. If you specify them
programmatically or declare them, then they get updated normally. If you
don't, then it renders the defaults (whether you like it or not). Since
inline styles override styles declared in the <head> or linked to an
external style sheet there is no good way to accomplish css. There is a
Color.Empty that had me going about a year ago, but it turns out that that
just renders black.

As a work around you can declare the styles that show up by default as
!important

For instance, background-color is always set to Silver in the SelectedDay
inline style. well in this example it still is inline as Silver but it will
actually show as green since the !imporatant overrides the inline style:

<head>
<style>
.Bob
{
font: 20pt times;
background-color: green !important;
}
</style>
</head>
<body>
<asp:Calendar id="Calendar1" runat="server">
<SelectedDayStyle CssClass="Bob" ></SelectedDayStyle>
</asp:Calendar>
</body>

having to use !imporatant to get styles to work with css, IMO, makes the
calendar a broken control. you could use grow your own css compliant
version of course or try to find a good one to purchase. If you are not a
stickler for CSS you could do this all manually by setting the
background-color programmatically, but it defeats the purpose of css
altogether at that point.

Maybe somebody else has figured out how to work around this problem.



manner,
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,969
Messages
2,570,161
Members
46,705
Latest member
Stefkari24

Latest Threads

Top