When developing enterprise ASP.NET applications, it is common to have a calendar booking facility. The calendar control supported by .NET and Visual Studio do not provide such a facility. Although the control can be customised, it does not offer the same level of sophistication and completeness offered by the calendar control presented here.
The control renders a calendar for the month/year selected. Each of the current/future days generate a postback event when selected, as does the rate combobox. The combobox dropdown menu is triggered by a right mouse button click.
- OnDayRender: Called for each rendered day. The program must return whether a day is "Available," "Booked," or "Unavailable."
- OnRateRender: Called for each rendered rate. The program must return "Rate" and "Available" strings (see the Using the Control section below for further details).
- OnSelectionChange: Called when a user request (postback event) is made for a day or rate change.
- Available day background colour
- Booked day background colour
- Heading month background colour
- Dropdown list hover colour
- Rate combobox colour
- Unavailable day colour
- Number of calendar columns
- Listbox entry string collection
- Rate length (maximum number of characters in string)
- Rate Combobox width
- Rate Combobox height
- Number of calendar rows
- Calendar Month
- Calendar Year
The demonstration application (CalTest) displays a 2 X 2 Calendar array starting from the current month (the example above was run on 3 July 2006). It generates a 53 week string array (rac) that holds availability and rate information that is intialised as available; in other words, all current dates with green backgrounds. The SelectionChange event updates this array through user request (postback event) for a day or rate change.
The control properties allow for a level of customisation and are fairly self explanatory. To use the control, the user will need to maintain information on booking availability and rates; the demonstration application (CalTest) shows a simple implementation of the control. Access to this data will be required when the control is rendered, the control generating events OnDayRender for day and OnRateRender for rate information.
There are two event arguments for OnDayRender, Date and Available. The Date argument is used to pass the day to be rendered and hence is used to recover the availability for that day. The Available argument is used by the control and hence must receive the availability status (Avail or Booked) for the requested day.
A postback event is generated when a user request is made for a day or rate change. The control, on receiving this postback event, uses the event argument to populate the SelectedRate, RateString, and SelectedDate properties. The control generates an OnSelectionChange event to the ASP.NET code-behind page, thereby enabling the application to update the maintained booking availability and rate data accordingly (see the demonstration application CalTest for further details).
The major part of the control is the rendering of the calander through a series of HTML tables. The MultiCal function is responsible for rendering multiple calendars and calls the function MonthCal for the rendering of each actual calendar. MonthCal is passed two parameters, CalMonth and CalYear; they are used to construct the calendar. The DayRenderStatus and RateRenderStatus functions generate the OnDayRender and OnRateRender events, respectively, into the main application to secure the requested information.
The ValidateTextbox function tests for a valid textbox entry and, if so, calls the _doPostBack function that generates a postback event. If the entry is not valid, an appropriate alert message box is displayed.
alert('The rate entry can only be a number or a listbox
alert('The rate cannot be left empty, please make a entry!');}