How to disable previous and future dates in ajax calendarextender v3.5?

Ezhilan picture Ezhilan · Sep 13, 2014 · Viewed 17.6k times · Source

I am using VS2008 with Ajax control toolkit v3.5 and i have used calendar extender tool in a textbox and When i click the textbox the calendar pops up and i shouldn't allow users to click previous or future dates from it.Only today date should be enabled and highlighted and all other dates should be disabled. I have gone through some suggestions but i couldn't get the exact result.

So anyone who might be able to help my situation will be greatly appreciated.

Answer

Ganesh_Devlekar picture Ganesh_Devlekar · Sep 13, 2014

To disable a past date use the following code in the "Page load":

add Header

<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit"
 TagPrefix="asp" %>

Markup:

<asp:CalendarExtenderID="Calendar1"runat="server" 
    Enabled="True" TargetControlID="TextBox1"Format="dd/MM/yyyy" ></asp:CalendarExtender>

protected void Page_Load(object sender, EventArgs e)
{
   Calendar1.StartDate = DateTime.Now;   //to dissable past Date
}

To disable a future date use the following code in the "Page load":

protected void Page_Load(object sender, EventArgs e)
{
   Calendar1.EndDate = DateTime.Now;   //to dissable future  Date
}