I was introduced to a cool
DHTML calendar control by a friend. I had been using
Tigra's calendar before this one, and it worked well. The Dynarch calendar is more robust, and offers more control than the first, so I decided to implement that option in the end. Getting either control to run within code was easy, so there was not an advantage nor disadvantage to one or the other.
After adding their javascript sources to your project, creating these calendars is just a matter of creating a link and providing an event. Since each control placed on a page requires its own unique ID, the only trick to creating dynamic calendars, or calendars from the server, is to generate the javascript for each calendar from the page's PreRender method. Since the UniqueID is not availible until PreRender, it makes sense to provide this UniqueID at this time.
In my scenario, I am placing my calendars in a DataGrid, so I use the DataGrid's PreRender event to set the javascript. I create a PlaceHolder for each, since I know there will be three calendars per each row in my grid. On PreRender, I find the PlaceHolder by ID, and add a new LiteralControl to the page containing my javascript with unique id's. Prior to this PreRender method, I have created my PlaceHolders and my Images to represent the calendars.
private void dgTimes_PreRender(object sender, System.EventArgs e)
{
foreach( DataGridItem item in dgTimes.Items )
{
if( item.FindControl("phOHD") != null )
{
PlaceHolder ph = (PlaceHolder)item.FindControl("phOHD");
ph.Controls.Add( new System.Web.UI.LiteralControl("<script language=\"javascript\">Calendar.setup({inputField:\"" +
ph.FindControl("OHD").UniqueID.Replace(":","_") + "\",ifFormat:\"%m/%d/%Y\",button:\"" +
ph.FindControl("OpenHouseDateImage").UniqueID.Replace(":","_") + "\",align:\"Tl\",singleClick:false,step:1});</script>") );
}
if( item.FindControl("phStartTime") != null )
{
PlaceHolder ph = (PlaceHolder)item.FindControl("phStartTime");
ph.Controls.Add( new System.Web.UI.LiteralControl("<script language=\"javascript\">Calendar.setup({inputField:\"" +
ph.FindControl("StartTime").UniqueID.Replace(":","_") + "\",ifFormat:\"%m/%d/%Y %I:%M %p\",showsTime:true,button:\"" +
ph.FindControl("StartTimeImage").UniqueID.Replace(":","_") +"\",align:\"Tl\",timeFormat:\"1\",singleClick:false,step:1});</script>") );
}
if( item.FindControl("phEndTime") != null )
{
PlaceHolder ph = (PlaceHolder)item.FindControl("phEndTime");
ph.Controls.Add( new System.Web.UI.LiteralControl("<script language=\"javascript\">Calendar.setup({inputField:\"" +
ph.FindControl("EndTime").UniqueID.Replace(":","_") + "\",ifFormat:\"%m/%d/%Y %I:%M %p\",showsTime:true,button:\"" +
ph.FindControl("EndTimeImage").UniqueID.Replace(":","_")+ "\",align:\"Tl\",timeFormat:\"12\",singleClick:false,step:1});</script>") );
}
}
}
Lastly, I replace the ':' character with '_' in my UniqueID because there appears to be a bug, although it is debatable, within dotnet. MSDN help says the UniqueID is separated by colons, but the Name property is actually separated by colons and the ID property is separated by underlines.
All in all, I find the Dynarch DHTML calendar to be pretty slick, as do my users.