In this article
I’m going to explain how to use Ajax Calendar Extender control in asp.net.
Ajax
Calendar Extender provides client side date picking functionality with
customizable date and UI in a popup control. You can interact with calendar by
clicking today date, past and future date.
Also
you can modify date format, popup display position and set custom styles to the
calendar.
Calender
properties:
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.
StartDate - Indicates start date for range that
available for selection.
EndDate - Indicates end date for range that
available for selection.
Designer
Source Code:
<%@ Page Language="C#"
AutoEventWireup="true"
CodeFile="Default.aspx.cs"
Inherits="_Default"
%>
<%@ Register Assembly="AjaxControlToolkit"
Namespace="AjaxControlToolkit"
TagPrefix="asp"
%>
<!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></title>
<style type="text/css">
.MyCalendar
.ajax__calendar_container
{
border:
1px solid #646464;
background-color:
lemonchiffon;
color:
red;
}
</style>
</head>
<body>
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<div>
<br />
<br />
<table width="600px"
align="center">
<tr>
<td colspan="2">
<b>Default
Calendar</b>
</td>
</tr>
<tr>
<td width="150px">
<asp:TextBox ID="txtDate1" runat="server"></asp:TextBox>
<asp:CalendarExtender ID="txtDate1_CalendarExtender1" runat="server"
Format="dd/MM/yyyy"
Enabled="True" TargetControlID="txtDate1"
PopupButtonID="txtDate1">
</asp:CalendarExtender>
</td>
</tr>
<tr>
<td colspan="2">
<b>Calendar with
an associated Image control:</b>
</td>
</tr>
<tr>
<td>
<asp:TextBox ID="txtDate" runat="server"></asp:TextBox>
</td>
<td>
<asp:Image ID="imgCalender" runat="server" ImageUrl="~/Images/Calender.png"
Height="30px"
Width="30px" />
<asp:CalendarExtender ID="txtDate_CalendarExtender" runat="server"
Format="dd/MM/yyyy"
Enabled="True" TargetControlID="txtDate"
PopupButtonID="imgCalender">
</asp:CalendarExtender>
</td>
</tr>
<tr>
<td colspan="2">
<b>Calendar with
a custom style:</b>
</td>
</tr>
<tr>
<td>
<asp:TextBox ID="txtDate2" runat="server"></asp:TextBox>
</td>
<td>
<asp:Image ID="Image1" runat="server" ImageUrl="~/Images/Calender.png" Height="30px"
Width="30px" />
<asp:CalendarExtender ID="CalendarExtender1" runat="server"
Format="dd/MM/yyyy"
Enabled="True"
TargetControlID="txtDate2"
PopupButtonID="Image1"
CssClass="MyCalendar">
</asp:CalendarExtender>
</td>
</tr>
</table>
</div>
</form>
</body>
</html>