Home All Groups Group Topic Archive Search About

Overriding Calendar.CreateChildControls

Author
17 Mar 2006 8:38 PM
krassimir
Hi All,

I am trying to subclass the Calendar Web Control to achieve the following. I
need to split each Calendar Cell in two parts - AM & PM parts. AM & PM parts
are populated by a List<TimeEntryDetail> custom collection. An user can click
in eather to adjust the entered information. I want to trach the Click &
DoubleClick events on the server.

I have tried hooking into the DayRender event, clearing the e.Cell.Controls
collection and adding two new custom controls TimeDetailDay which define
Click & DoubleClick events and know how to render the AM & PM part
respectively.  That gave me the desired calendar look but the events did not
fire.

I gues I need to derive a custom control from Calendar and override the
CretaeChildControls method. The thing is there is no way to get a hold of the
internal Table control that's used to hold the calendar cells.

Any advise on how to approach this is very appreciated. Or do I just need to
write a custom calendar control from scratch in order to do this?

Krassimir

Author
19 Mar 2006 9:10 PM
Phillip Williams
Hello Krassimir,

The DayRender event is triggered later than the page initialization stage
and therefore any dynamically added controls will not retain their ViewState
upon postback. 

“Because the DayRender event is raised while the Calendar control is being
rendered, you cannot add a control that can also raise an event, such as
LinkButton. You can only add static controls, such as
System.Web.UI.LiteralControl, Label, Image, and HyperLink.” http://msdn2.microsoft.com/en-us/library/system.web.ui.webcontrols.calendar.dayrender(VS.80).aspx

However, using the advice of Microsoft, as quoted above, you can use static
controls in combination with some JavaScript to generate a postback event
from another server control on the web form to achieve the same effect. 

Here is one demonstration of such a programming strategy for this task:
http://www.webswapp.com/codesamples/aspnet20/calendar/default.aspx

Show quoteHide quote
"krassimir" wrote:

> Hi All,
>
> I am trying to subclass the Calendar Web Control to achieve the following. I
> need to split each Calendar Cell in two parts - AM & PM parts. AM & PM parts
> are populated by a List<TimeEntryDetail> custom collection. An user can click
> in eather to adjust the entered information. I want to trach the Click &
> DoubleClick events on the server.
>
> I have tried hooking into the DayRender event, clearing the e.Cell.Controls
> collection and adding two new custom controls TimeDetailDay which define
> Click & DoubleClick events and know how to render the AM & PM part
> respectively.  That gave me the desired calendar look but the events did not
> fire.
>
> I gues I need to derive a custom control from Calendar and override the
> CretaeChildControls method. The thing is there is no way to get a hold of the
> internal Table control that's used to hold the calendar cells.
>
> Any advise on how to approach this is very appreciated. Or do I just need to
> write a custom calendar control from scratch in order to do this?
>
> Krassimir