Home / AJAX

Page History: HOW TO Use the Calendar Control

Compare Page Revisions



« Older Revision - Back to Page History - Newer Revision »


Page Revision: 2009/12/21 22:27


Calendar Demonstration



Calendar Description

The Calendar control enables you to display date picker when focus is moved to an input element.

Image

Calendar is an ASP.NET AJAX extender that can be attached to any ASP.NET TextBox control. It provides client-side date-picking functionality with customizable date format and UI in a popup control. You can interact with the calendar by clicking on a day to set the date, or the "Today" link to set the current date.

In addition, the left and right arrows can be used to move forward or back a month. By clicking on the title of the calendar you can change the view from Days in the current month, to Months in the current year. Another click will switch to Years in the current Decade. This action allows you to easily jump to dates in the past or the future from within the calendar control.

Video - How Do I: Configure the ASP.NET AJAX Calendar Control?

Calendar Client Code Sample

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" > <head runat="server"> <title>Untitled Page</title> <style type="text/css"> </style> <link href="http://ajax.microsoft.com/ajax/beta/0911/extended/Calendar/Calendar.css" rel="stylesheet" type="text/css" /> <script src="http://ajax.microsoft.com/ajax/jquery/jquery-1.3.2.js" type="text/javascript"></script> <script src="http://ajax.microsoft.com/ajax/beta/0911/Start.debug.js" type="text/javascript"></script> <script src="http://ajax.microsoft.com/ajax/beta/0911/extended/ExtendedControls.debug.js" type="text/javascript"></script> <script type="text/javascript"> Sys.debug = true; Sys.require(Sys.components.calendar, function() { $("#bdate").calendar({}); }); </script> </head> <body> <div style="width:1px;height:500px"></div> <input type="text" id="bdate" /> </body> </html>

Calendar Client Properties

Calendar Sever Code Sample

        <asp:TextBox runat="server" ID="Date5" />
        <asp:ImageButton runat="Server" ID="Image1" ImageUrl="~/images/Calendar_scheduleHS.png" 
                         AlternateText="Click to show calendar" /><br />
        <ajaxToolkit:CalendarExtender ID="calendarButtonExtender" runat="server" 
                     TargetControlID="Date5" PopupButtonID="Image1" />

Calendar Server Properties

The properties in italics are optional.

<ajaxToolkit:Calendar runat="server"
    TargetControlID="Date1"
    CssClass="ClassName"
    Format="MMMM d, yyyy"
    PopupButtonID="Image1" />

  • TargetControlID - The ID of the TextBox to extend with the calendar.
  • CssClass - Name of the CSS class used to style the calendar. See the Calendar Theming section for more information.
  • Format - Format string used to display the selected date.
  • PopupButtonID - The ID of a control to show the calendar popup when clicked. If this value is not set, the calendar will pop up when the textbox receives focus.
  • PopupPosition - Indicates where the calendar popup should appear at the BottomLeft(default), BottomRight, TopLeft, TopRight, Left or Right of the TextBox.
  • SelectedDate - Indicates the date the Calendar extender is initialized with.

Calendar Additional Code Samples