Export (0) Print
Expand All

Calendar Class

Provides control capability to display a calendar.

Namespace: System.Web.UI.MobileControls
Assembly: System.Web.Mobile (in system.web.mobile.dll)

public class Calendar : MobileControl, IPostBackEventHandler
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.

NoteNote

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="C#" 
    Inherits="System.Web.UI.MobileControls.MobilePage" %>
<%@ Import Namespace="System.Drawing" %>
<%@ Register TagPrefix="mobile" 
    Namespace="System.Web.UI.MobileControls" 
    Assembly="System.Web.Mobile" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" 
    "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">

<script runat="server">
    protected void Page_Load(object sender, EventArgs e)
    {
        // Display the day header
        Calendar1.ShowDayHeader = true;
        
        // This allows the user to select a week or a month at a time.
        Calendar1.SelectionMode =
           CalendarSelectionMode.DayWeekMonth;
        // Set the BorderStyle and BorderColor properties.
        Calendar1.WebCalendar.DayStyle.BorderStyle =
           BorderStyle.Solid;
        Calendar1.WebCalendar.DayStyle.BorderColor = Color.Cyan;

        Calendar1.CalendarEntryText = "Your birthdate";
        
        Calendar1.VisibleDate = DateTime.Parse("7/1/" + 
            DateTime.Now.Year.ToString());
    }

    protected void ShowChanges(Object sender, EventArgs e)
    {
        TextView1.Text = "The date you selected is " +
           Calendar1.SelectedDate.ToShortDateString();
        
        // Distinguish the selected block using colors.
        Calendar1.WebCalendar.SelectedDayStyle.BackColor =
           Color.LightGreen;
        Calendar1.WebCalendar.SelectedDayStyle.BorderColor =
           Color.Gray;
        Calendar1.WebCalendar.DayStyle.BorderColor = Color.Blue;
    }

    protected void Command1_Click(object sender, EventArgs e)
    {
        int currentDay = Calendar1.VisibleDate.Day;
        int currentMonth = Calendar1.VisibleDate.Month;
        int currentYear = Calendar1.VisibleDate.Year;
        Calendar1.SelectedDates.Clear();

        // Add all Wednesdays to the collection.
        for (int i = 1; i <= System.DateTime.DaysInMonth(currentYear,
               currentMonth); i++)
        {
            DateTime targetDate = new DateTime(currentYear, currentMonth, i);
            if (targetDate.DayOfWeek == DayOfWeek.Wednesday)
                Calendar1.SelectedDates.Add(targetDate);
        }
        TextView1.Text = "Selection Count ="
           + Calendar1.SelectedDates.Count.ToString();
    }
</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
<body>
    <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 Wednesdays</mobile:Command>
    </mobile:form>
</body>
</html>

System.Object
   System.Web.UI.Control
     System.Web.UI.MobileControls.MobileControl
      System.Web.UI.MobileControls.Calendar

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

ADD
Show:
© 2014 Microsoft