Introduction to the Calendar Web Server Control
The Calendar Web server control can serve these purposes:
- Display and select dates The control displays a calendar through which users can navigate to any day in any year. Setting the SelectedDate Property property causes a specific date to be highlighted in the control. Optionally, users can move to arbitrary dates by clicking a day or moving from month to month. The calendar can be configured to allow users to select multiple dates, either an entire week or an entire month.
Typical uses are to graphically display the current date on a daily news Web page, or to allow users to select dates in scheduling applications to order airline reservations, concert tickets, and so on.
A representation of the Calendar control displaying the month of October
- Display appointment or other information in a calendar grid The Calendar control can display day-specific details for individual days, such as a to-do list, a schedule of events, or similar information. This feature allows you to display day information from a database.
The Calendar control is based around the .NET framework DateTime object, and therefore supports the full range of dates allowed by that object. Effectively, you can display any date between the years 0 and 9999 A.D.
Note In Visual Basic the Date data type is equivalent to the .NET framework's DateTime data type.
The Calendar control is rendered as an HTML table when the Web Forms page runs. Therefore, a number of the control's properties pertain to various aspects of table formatting. A few of these properties are not fully supported in some older browsers, so some formatting features will not be available in those browsers.
Developing with the Calendar Web Server Control
The following sections contain details about how the Calendar control works and an overview of tasks you can accomplish with it.
Displaying and Selecting Dates
The Calendar control displays a month of dates at a time, with a total of six weeks appearing at once. Within the control, there are several types of dates that you can work with:
|Type of date||Description|
|Today's date||By default, the current date on the server. However, you can adjust it so that the date appears correctly for a different locale.|
|Visible date||This date determines what month appears in the calendar. The user can move from month to month on the calendar, thereby changing the visible date without affecting today's date. You can navigate between months by setting the visible date programmatically.|
|Selected date or dates||This is the date or date range that the user chooses. In the control, the user can choose a single day, week, or month, but can only select contiguous dates. You can also programmatically set the selected dates; in that case, you can set non-contiguous selected dates.|
Enabling Date Selection
By default, the calendar allows users to click an individual date to select it. If you are using the control as a read-only calendar, you can disable all date selection.
If day selection is enabled, each day of the calendar contains a LinkButtoncontrol that raises an event when clicked. If you enable week or month selection, a column of links is added to the left side of the calendar to enable the user to specify what week to select.
Customizing the Calendar's Appearance
You can set calendar properties to change the colors, size, text, and other visual features of the calendar. There are a number of ways to do this:
|Setting properties||You can set properties to display grid lines, change what day is displayed as the first day of the week, and change the appearance of the month and day names.|
|Setting extended style properties||You can use properties derived from the Style object to set the appearance of particular elements in the calendar, such as the current date or the title bar containing the month and navigation links. These style properties are supported in browsers that can use cascading style sheets; a reduced set of appearance styles is supported for earlier browsers.|
|Customizing the rendering of individual days||As the control renders individual days, it raises an event you can handle to modify the stream being rendered to the browser. This is useful not just for changing the appearance of days, but for including custom content on each day as well.|
Capturing User Interaction with the Calendar Web Server Control
The Calendar control raises an event when the user selects an individual date or range of dates or navigates to a new month. By creating methods for these events, you can determine what day or dates the user has selected and respond appropriately. One response may be to customize the display of that date. In creating a custom display, you can include any HTML elements in the calendar, including other server controls.
Displaying Information from a Database in the Calendar Control
A common scenario is to display information from a database in the calendar. For example, an events calendar is often based out of information kept in a database.
The Calendar control does not directly support databinding — that is, you do not bind the calendar as a whole to a data source. Instead, you create a method for the control's DayRender event, which is raised as each day in the current calendar month (view) is being rendered. In the method for this event, you can extract information from a data source and add it to the stream being sent to the browser.