Export (0) Print
Expand All
2 out of 4 rated this helpful - Rate this topic

Calendar Class

Displays a single month calendar that allows the user to select dates and move to the next or previous month.

For a list of all members of this type, see Calendar Members.

System.Object
   System.Web.UI.Control
      System.Web.UI.WebControls.WebControl
         System.Web.UI.WebControls.Calendar

[Visual Basic]
Public Class Calendar
   Inherits WebControl
   Implements IPostBackEventHandler
[C#]
public class Calendar : WebControl, IPostBackEventHandler
[C++]
public __gc class Calendar : public WebControl,
   IPostBackEventHandler
[JScript]
public class Calendar extends WebControl implements
   IPostBackEventHandler

Thread Safety

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Remarks

Use the Calendar control to display a single month of a calendar on a Web page. The control allows you to select dates and move to the next or previous month. The Calendar control supports all the System.Globalization.Calendar types in the System.Globalization namespace. Apart from the Gregorian calendar, this also includes calendars that use different year and month systems, such as the Hjiri calendar.

You can specify whether the Calendar control allows you to select a single day, week, or entire month by setting the SelectionMode property.

By default, the control displays the days of the month, day headings for the days of the week, a title with the month name and year, links for selecting individual days of the month, and links for moving to the next and previous month. You can customize the appearance of the Calendar control by setting the properties that control the style for different parts of the control. The following table lists the properties that specify the style for the different parts of the control.

Property Description
DayHeaderStyle Specifies the style for the section that displays the days of the week.
DayStyle Specifies the style for the dates in the displayed month.
NextPrevStyle Specifies the style for the navigation controls in the title section.
OtherMonthDayStyle Specifies the style for the dates that are not in the currently displayed month.
SelectedDayStyle Specifies the style for the selected dates on the calendar.
SelectorStyle Specifies the style for the week and month date selection column.
TitleStyle Specifies the style for the title section.
TodayDayStyle Specifies the style for today's date.
WeekendDayStyle Specifies the style for the weekend dates.

You can also show or hide different parts of the control. The following table lists the properties that control which parts are shown or hidden.

Property Description
ShowDayHeader Shows or hides the section that displays the days of the week.
ShowGridLines Shows or hides the grid lines between the days of the month.
ShowNextPrevMonth Shows or hides the navigation controls to the next or previous month.
ShowTitle Shows or hides the title section.

Although binding to a data source is not supported for the Calendar control, you can modify the content and formatting of the individual date cells. Before the Calendar control is displayed on the Web page, it creates and assembles the components that make up the control. The DayRender event is raised when each date cell in the Calendar control is created. You can control the contents and formatting of a date cell as it is created by providing code in the event handler for the DayRender event. For additional information on customizing the contents of a date cell, see OnDayRender.

Note   The Calendar control renders JavaScript to the client browser. The client browser must have JavaScript enabled for this control to function properly. For more information on client script, see Client Script in Web Forms Pages.

Example

[Visual Basic, C#, JScript] The following example demonstrates how to create a Calendar control on a Web page.

[Visual Basic] 
<%@ Page Language="VB" AutoEventWireup="True" %>
<html>
<head>

</head>
<body>

   <form runat="server">

      <asp:Calendar id="calendar1" runat="server">

           <OtherMonthDayStyle ForeColor="LightGray">
           </OtherMonthDayStyle>

           <TitleStyle BackColor="Blue"
                       ForeColor="White">
           </TitleStyle>

           <DayStyle BackColor="gray">
           </DayStyle>

           <SelectedDayStyle BackColor="LightGray"
                             Font-Bold="True">
           </SelectedDayStyle>

      </asp:Calendar>
            
   </form>
        
</body>
</html>
   

[C#] 
<%@ Page Language="C#" AutoEventWireup="True" %>
<html>
<head>

</head>
<body>

   <form runat="server">

      <asp:Calendar id="calendar1" runat="server">

           <OtherMonthDayStyle ForeColor="LightGray">
           </OtherMonthDayStyle>

           <TitleStyle BackColor="Blue"
                       ForeColor="White">
           </TitleStyle>

           <DayStyle BackColor="gray">
           </DayStyle>

           <SelectedDayStyle BackColor="LightGray"
                             Font-Bold="True">
           </SelectedDayStyle>

      </asp:Calendar>
            
   </form>
        
</body>
</html>
   

[JScript] 
<%@ Page Language="JScript" AutoEventWireup="True" %>
<html>
<head>

</head>
<body>

   <form runat="server">

      <asp:Calendar id="calendar1" runat="server">

           <OtherMonthDayStyle ForeColor="LightGray">
           </OtherMonthDayStyle>

           <TitleStyle BackColor="Blue"
                       ForeColor="White">
           </TitleStyle>

           <DayStyle BackColor="gray">
           </DayStyle>

           <SelectedDayStyle BackColor="LightGray"
                             Font-Bold="True">
           </SelectedDayStyle>

      </asp:Calendar>
            
   </form>
        
</body>
</html>
   

[C++] No example is available for C++. To view a Visual Basic, C#, or JScript example, click the Language Filter button Language Filter in the upper-left corner of the page.

Requirements

Namespace: System.Web.UI.WebControls

Platforms: Windows 2000, Windows XP Professional, Windows Server 2003 family

Assembly: System.Web (in System.Web.dll)

See Also

Calendar Members | System.Web.UI.WebControls Namespace | SelectionMode | DayHeaderStyle | DayStyle | NextPrevStyle | OtherMonthDayStyle | SelectedDayStyle | SelectorStyle | TitleStyle | TodayDayStyle | WeekendDayStyle | ShowDayHeader | ShowGridLines | ShowNextPrevMonth | ShowTitle | Client Script in Web Forms Pages

Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft. All rights reserved.