O'Reilly logo

Programming ASP.NET, 3rd Edition by Dan Hurwitz, Jesse Liberty

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Calendar

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" %>
 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
   "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
 
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>Calendar - Simple</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
      <h1>Calendar Control</h1>
      <h2>Default Calendar</h2>

       <asp:Calendar ID="Calendar1" runat="server"></asp:Calendar>
    </div>
    </form>
</body>
</html>
A default Calendar control

Figure 5-14. A default Calendar ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required