Calendar Class
Collapse the table of content
Expand the table of content

Calendar Class

Provides control capability to display a calendar.

Namespace: System.Web.UI.MobileControls
Assembly: System.Web.Mobile (in

Public Class Calendar
	Inherits MobileControl
	Implements IPostBackEventHandler
Dim instance As Calendar

public class Calendar extends MobileControl implements IPostBackEventHandler
public class Calendar extends MobileControl implements IPostBackEventHandler

The calendar display is by day, week, or month. Whether an entire month is rendered on a mobile device depends on the capabilities of the device. In general, the Calendar control permits the selection of a date.

The mobile Calendar control wraps a Web Forms Calendar control. Although the mobile Calendar control mimics some properties, methods, and events of the underlying control, it does not expose other properties specific to HTML rendering. To modify these, you can access the underlying control through the WebCalendar property and modify the settings directly.

The following code example shows how the SelectionMode property in the page load code block allows the user to select a day, a week, or a month block of time. This example sets the BorderStyle and BackColor properties of the Calendar class to distinguish the user selection.


The following code sample uses the single-file code model and may not work correctly if copied directly into a code-behind file. This code sample must be copied into an empty text file that has an .aspx extension. For more information, see ASP.NET Web Page Code Model.

<%@ Page Language="VB"
    Inherits="System.Web.UI.MobileControls.MobilePage" %>
<%@ Import Namespace="System.Drawing" %>
<%@ Import Namespace="System.Web.UI.WebControls" %>
<%@ Register TagPrefix="mobile"
    Assembly="System.Web.Mobile" %>


<script runat="server">
    Protected Sub Page_Load(ByVal sender As Object, _
        ByVal e As System.EventArgs) Handles Me.Load

        ' Display the day header
        Calendar1.ShowDayHeader = True

        ' Allow the user to select a week or a month at a time.
        Calendar1.SelectionMode = _

        ' Set the BorderStyle and BorderColor properties.
        Calendar1.WebCalendar.DayStyle.BorderStyle = _
        Calendar1.WebCalendar.DayStyle.BorderColor = Color.Cyan

        Calendar1.CalendarEntryText = "Your birthdate"
        Calendar1.FirstDayOfWeek = _
        Calendar1.VisibleDate = DateTime.Parse("7/1/2004")

    End Sub

    Protected Sub ShowChanges(ByVal sender As Object, _
        ByVal e As EventArgs)

        TextView1.Text = "The date you selected is " & _

        ' Distinguish the selected block using colors.
        Calendar1.WebCalendar.SelectedDayStyle.BackColor = _
        Calendar1.WebCalendar.SelectedDayStyle.BorderColor = _
        Calendar1.WebCalendar.DayStyle.BorderColor = Color.Blue
    End Sub

    Protected Sub Command1_Click(ByVal sender As Object, ByVal e As System.EventArgs)
        Dim currentDay As Integer = Calendar1.VisibleDate.Day
        Dim currentMonth As Integer = Calendar1.VisibleDate.Month
        Dim currentYear As Integer = Calendar1.VisibleDate.Year
        ' Loop through current month and add all Wednesdays to the collection.
        Dim i As Integer
        For i = 1 To System.DateTime.DaysInMonth(currentYear, currentMonth)
            Dim targetDate As New DateTime(currentYear, currentMonth, i)
            If targetDate.DayOfWeek = DayOfWeek.Wednesday Then
            End If
        Next i
        TextView1.Text = "Selection Count = " & Calendar1.SelectedDates.Count.ToString()
    End Sub

<html xmlns="" >
    <mobile:form id="form1" runat="server">
        <mobile:Calendar id="Calendar1" runat="server"
            OnSelectionChanged="ShowChanges" />
        <mobile:TextView runat="server" id="TextView1" />
        <mobile:Command ID="Command1" OnClick="Command1_Click" Runat="server">Select Weekdays</mobile:Command>


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

Windows 98, Windows 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see System Requirements.

.NET Framework

Supported in: 2.0, 1.1

Community Additions

© 2015 Microsoft