In this article I will explain with an example, how to disable Future date selection in
AJAX CalendarExtender control in ASP.Net using C# and VB.Net.
Installing AjaxControlToolkit package using Nuget
HTML Markup
The HTML Markup consists of following controls:
ScriptManager – For enabling ASP.Net
AJAX.
TextBox – For capturing the user input.
ImageButton – For displaying calendar icon.
CalendarExtender – For displaying calendar.
The
AJAX CalendarExtender has been assigned with the following properties:
TargetControlID – For defining control to set selected date. Here it is TextBox.
PopupButtonID – For defining control on click of which the calendar appears.
Disabling Future date in ASP.Net AJAX CalendarExtender
The
AJAX CalendarExtender has been assigned with the following property.
EndDate – For disabling the Future date selection.
Dates after the Date set in the EndDate property will be disabled, which means it cannot be selected.
<asp:ScriptManager ID="ScriptManager1" runat="server" />
<asp:TextBox ID="txtDate" runat="server" />
<asp:ImageButton ID="imgPopup" runat="server" ImageUrl="~/Image/calendar.gif" />
<ajaxToolkit:CalendarExtender ID="Calender1" runat="server" TargetControlID="txtDate" PopupButtonID="imgPopup" EndDate="12/30/2024" />
The above property can be set through Code-Behind in following way:
C#
//Disable Future Date
Calender1.EndDate = DateTime.Now;
VB.Net
'Disable Future Date
Calender1.EndDate = DateTime.Now
Screenshot
Demo
Downloads