Alex Mueller on Software and Technology 
Wednesday, December 22, 2004
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.

Wednesday, December 22, 2004 10:18:15 AM (Mountain Standard Time, UTC-07:00) | Comments [0] | #
MuellerDesigns.net
Search
On This Page
SketchPath XPath Editor
Software Testing - Revisited
Architecting Buildings and Software
NBCOlympics.com with Silverlight
Marker Interfaces and C# Attributes
The Phone Screen
Working with ASP.NET MVC and MvcContrib
Thanks to BDD
Twitter
The Opposite of a Singleton?
Removing Duplicate Code in Functions
Add Vista Themes to Longhorn
Changing File Ownership In Vista and Longhorn
ReSharper Type Completion
Caring for the Team
Most Popular
JavaScript ReplaceAll Functionality
What is polymorphism?
What is composition?
Sorting with IComparable and IComparer
Applying the Observer Pattern in ASP.NET
MVP in ASP.NET
What is abstraction?
What is encapsulation?
What is a class?
What is inheritance?
Authentication in ASP.NET
Calendar Controls
SQL Server 2005 Connection Issues
XPathNavigator.CheckValidity new for 2.0
Auto-attach to process '[####] aspnet_wp.exe' on m...
What is an object?
FreeTextBox
VMWare and VPC
An Example of Reflection using C#
A New NHibernate Blog
Archive
Links
Categories
My Local Blog Map
Blogroll
About
Powered by:

Disclaimer
The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.

© Copyright 2008
MuellerDesigns.net

Sign In

Help Those In Need
The Hunger Site
Ronald McDonald House Charities (RMHC) of Western Washington & Alaska