Home > Ajax, Asp.net, Javascript > Asp.net Ajax Calendar Extender and Past Date Validation Javascript

Asp.net Ajax Calendar Extender and Past Date Validation Javascript

When using asp.net ajax calendar extender, we want to restrict users from selecting dates in the past.So to achieve that we have to make use of OnClientDateSelectionChanged  event of calendarextender.Below is the code.

<script language=”javascript” type=”text/javascript”>

function CheckForPastDate(sender, args) {

var selectedDate = new Date();

selectedDate = sender._selectedDate;

var todayDate = new Date();

if (selectedDate.getDateOnly() < todayDate.getDateOnly()) {

sender._selectedDate = todayDate;                  sender._textbox.set_Value(sender._selectedDate.format(sender._format));

alert(“Date Cannot be in the past”);




<asp:TextBox ID=”txtDate” contentEditable=”false” runat=”server” CssClass=”txtcss”></asp:TextBox>&nbsp;

<asp:Image ID=”imgCal” runat=”server” ImageUrl=”~/img/calendar.gif” />

<cc1:CalendarExtender ID=”CalExtDate” runat=”server” FirstDayOfWeek=”Sunday” PopupButtonID=”imgCal”PopupPosition=”BottomLeft” Format=”dd/MM/yyyy” OnClientDateSelectionChanged=”CheckForPastDate” TargetControlID=”txtDate”>


  1. January 8, 2010 at 7:09 pm

    I cannot believe this is true!

  2. January 11, 2010 at 7:06 pm

    Damn, that sound’s so easy if you think about it.

  3. March 6, 2010 at 3:30 pm

    nice tuto in here , good introduction , look at mine in my website righ here http://help.uk.cm.

    hear from you soon thanks

  4. March 14, 2012 at 11:38 am

    Thanks for tip, documentation on the ajax toolkit seems a little more sparse

  5. sureka
    July 26, 2012 at 11:52 am

    its true it is working i tested thnx

  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: