The ASP Calendar control is a rich web control that provides several capabilities:

  • Displays a calendar showing a single month

  • Allows the user to select a day, week, or month

  • Allows the user to select a range of days

  • Allows the user to move to the next or previous month

  • Programmatically controls the display of specific days

The Calendar control is customizable, with various properties and events. Before digging into all the detail, look at a bare bones .aspx file showing a simple Calendar control, along with the resulting web page. Create a new web site called Calendar-Simple, and drag a Calendar control onto the page.

Example 5-16 contains the code with the Calendar declaration highlighted, and Figure 5-14 shows the results. There is no code-behind file with this example other than the default boilerplate created by VS2005.

Example 5-16. Default.aspx for Calendar-Simple

<%@ Page Language="C#" AutoEventWireup="true"  CodeFile="Default.aspx.cs"
   Inherits="_Default" %>
<html xmlns="" >
<head runat="server">
    <title>Calendar - Simple</title>
    <form id="form1" runat="server">
      <h1>Calendar Control</h1>
      <h2>Default Calendar</h2>

       <asp:Calendar ID="Calendar1" runat="server"></asp:Calendar>
A default Calendar control

Figure 5-14. A default Calendar ...

Get Programming ASP.NET, 3rd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.