very nice. Works with most browsers, but sophisticated with Chrome 11.0.696.71 and Safari for windows (not tested on Mac)
For several months, the calendar control shows an extra week at the beginning of the month. (when the first month is the first day of the week.)
When you set e.cell.Visible = false, it does not display elements. So, in chrome, you get the string <tr></tr> . Chrome displays this as an empty string. And since I donβt think there is a way to set the height / style of the TR element using the calendar control, you will get an ugly calendar that skips the first line for certain months.
Also setting the height to 0 does nothing if you set Visible = false. If you don't set Visible = false and just put height = 0, it still won't display correctly in chrome. So the solution is to set the height to 1
Here is my modified solution.
therurender
protected void Calendar1_DayRender(object sender, DayRenderEventArgs e){ hideExtraWeek(sender, e, (DayOfWeek)Calendar1.FirstDayOfWeek); }
function
protected void hideExtraWeek(object sender, DayRenderEventArgs e, DayOfWeek dw){ if (dw == (DayOfWeek)7) dw = (DayOfWeek)0; // FirstDayOfweek returns 7 when set to default, But it zero based so valid values are 0 to 6 Boolean blnBrowserDoesntSupportsEmptyRow= Request.Browser.Browser=="Chrome" || Request.Browser.Browser=="Safari"; int dayOfWeek = Convert.ToInt16(e.Day.Date.DayOfWeek); int compensate = dayOfWeek - Convert.ToInt16(dw); DateTime WeekStart = e.Day.Date.AddDays(-1 * compensate); DateTime WeekEnd = WeekStart.AddDays(6); // If the start and end of the week does not have relevance to the current month if (WeekStart.Month==WeekEnd.Month && e.Day.IsOtherMonth){ e.Cell.Text = ""; e.Cell.Height = 1; // fix for chrome. Visible=false leaves a blank row even when there are no <td>s in the <tr> e.Cell.Visible = blnBrowserDoesntSupportsEmptyRow; } }
robert
source share