Share via


Calendar

The Calendar control displays a calendar through which users can navigate to any day in any year. When the ASP.NET page runs, the Calendar control is rendered as an HTML table. 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 not all of the formatting features will be available in those browsers.

The Calendar control is a fairly complex control and has a lot of programming and formatting options. For details about using the Calendar control, see Calendar Web Server Control (Visual Studio) Cc295478.xtlink_newWindow(en-us,Expression.40).png in the MSDN library.

To add a Calendar control to a page

  • Drag the Calendar control from the Toolbox panel to your page.

To apply basic formatting schemes to the Calendar control

  1. In Design view, right-click the Calendar control, and then click ShowCommonControlTasks****.

    Tip

    You can also click the Calendar control in Design view, click the arrow Cc295478.56557a2a-a4ef-4c47-906b-f64b8d530387(en-us,Expression.40).png in the upper-right corner to show the Common Calendar Tasks menu. Click the arrow again to hide the menu.

  2. On the Common Calendar Tasks menu, click AutoFormat.

  3. In the AutoFormat dialog box, select one of the schemes in the Select a scheme list. The effect of the scheme on your Calendar control is displayed in the Preview area.

  4. Click OK to apply the formatting scheme and close the dialog, or Apply to apply the formatting scheme without closing the dialog.

To set other properties that determine the appearance and behavior of the Calendar, use the Tag Properties panel.

To use the Tag Properties panel to set Calendar properties

  1. Right-click the Calendar control in Design view and click Properties in the shortcut menu.

  2. Type property values, or select them from dropdown lists where they are available.

For a full description of all Calendar control properties, see Calendar Properties Cc295478.xtlink_newWindow(en-us,Expression.40).png in the MSDN library.

Calendar Functionality

You can set properties to specify the way users can interact with the Calendar.

Common Calendar functionality properties

Properties Description

SelectedDate

Causes a specific date to be highlighted in the control.

ShowNextPrevMonth

Enables or disables user month navigation. By default, the calendar displays the month containing today's date. Users can move from month to month in the Calendar control by clicking month navigation links in the title bar of the calendar. If the property is false, the control does not display the controls in the title that allow a user to move between months.

SelectionMode

Set this property to one of the values defined in the SelectionMode enumeration: Day, DayWeek, or DayWeekMonth to specify what a user can select. To disable all date selection, set the property to None. To allow the user to select a date, the calendar is displayed with links. Individual days contain a link with the date number. If you set the calendar to allow users to select a week or the whole month, an extra column with selection links is added to the left of the calendar.

VisibleDate

This date determines which 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.

Changing General Calendar Appearance

Because the Calendar control is a complex control made up of many individual elements, it offers you a wide variety of options for customizing its appearance.

The Calendar control establishes a default look for the calendar on the page, but you can change the calendar's overall appearance. If you set appearance properties for individual calendar elements, such as today's date, the selected date, and so on, the individual settings are based on the default settings you make for the calendar as a whole.

Common Calendar appearance properties

Properties Description

Font, ForeColor, BackColor

Change the font, text and background color.

Height, Width

Change overall control size.

NextMonthText, PrevMonthText, NextPrevFormat, NextPrevStyle

Changes the appearance of the month-navigation hyperlinks.

CellPadding, CellSpacing

Change margins and spacing around individual days.

FirstDayOfWeek

Specify which day starts the week (default is Sunday).

DayStyle

Set the style for days of the current month. Weekends, today, and the selected day can have different styles.

DayHeaderStyle

Set the style for the row above the calendar where the names of the days appear.

NextPrevStyle

Set the style for the sections at the left and right ends of the title bar where the month-navigation LinkButtons are.

OtherMonthDayStyle

Set the style for the days from the previous and next month that appear on the current month view.

SelectedDayStyle

Set the style for the day selected by the user.

SelectorStyle

Set the style for the column to the left containing links for selecting a week or the whole month.

TitleStyle

Set the style for the title bar at the top of the calendar containing the month name and month navigation links. If NextPrevStyle is set, it overrides the extreme ends of the title bar.

TodayDayStyle

Set the style for today's date.

WeekendDayStyle

Set the style for weekend days.

For more information about the Calendar control, see Calendar Web Server Control Overview Cc295478.xtlink_newWindow(en-us,Expression.40).png in the MSDN library.

Send feedback about this topic to Microsoft. © 2011 Microsoft Corporation. All rights reserved.