Home > AJAX, ASP.Net > Disable Past Dates in AJAX Calender

Disable Past Dates in AJAX Calender

Hi all,

In previous post i show you how to allow user to select only first date of month

Allow User to Select only First day of month in AJAX Calender

in this post i will show how to prevent user to select past dates in AJAX Calender

1) Open VS2008 and create a new website

2) Add new Page and from Toolbox drag ScriptManager , TextBox and AJAX Calender Controls.

3) Add This Javascript function

<script type="text/javascript">
 function checkDate(sender, args) {
 if (sender._selectedDate < new Date()) {
 alert("You cannot select a day earlier than today!");
 sender._selectedDate = new Date();
 // set the date back to the current date

4) Your page will be like this

<asp:ScriptManager ID="ScriptManager1" runat="server">
 Please Select Date
 <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
 <asp:CalendarExtender ID="CalendarExtender1" BehaviorID="CalendarExtender1" runat="server"
 TargetControlID="TextBox1" PopupButtonID="TextBox1" OnClientDateSelectionChanged="checkDate">

Hope this helps

Good Luck

Categories: AJAX, ASP.Net
  1. No comments yet.
  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: