I do not think that the current version of Toolkit supports a restriction on the selected dates. This is a simple workaround to process ClientDateSelectedChanged -Event and check the selected date:
How to make sure that the user does not select a date earlier than today or more than today
There may be times when you do not want the user to select a day earlier than the current date. For example: when you provide the user with a form for booking tickets, you would not want him to choose an earlier date. To achieve this requirement, use the following javascript code.
Prevent the user from choosing a date earlier than today
<head runat="server"> <title>Calendar Extender</title> <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(); </script> </head>
Call code:
<form id="form1" runat="server"> <asp:ScriptManager ID="ScriptManager1" runat="server" /> <div> <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox> <cc1:CalendarExtender ID="CalendarExtender1" runat="server" OnClientDateSelectionChanged="checkDate" TargetControlID="TextBox1" /> </div> </form>
Choose a date More than today
In javascript just change this line sender._selectedDate > new Date() Note. You can claim that the user can change the date by entering a text field or by entering an invalid date. Well, that can be easily handled using ValidationControl and will be covered in the next tip.
Add check on CalendarExtender control
An easy way to add validation to Calendar is to add a ValidationControl to the text field associated with CalendarExtender. You have two options:
- Add
Extender to ValidationControl . To do this, drag the ValidationControl > icon onto the ValidationControl smart tag> select Add Extender . In the Extension ValidatorCalloutExtender select ValidatorCalloutExtender . Using this approach, it is extremely easy to detect and attach controls to your controls. In VS 2005, you had to perform this process manually by connecting control expanders. - You can not add Extender. We will continue option A. We will add two
ValidationControls to the TextBox . Firstly, a CompareValidator to check if the user is entering an invalid date (for example: May 32), and secondly, RangeValidator to keep the date range as desired.
Adding CompareValidator
<asp:CompareValidator ID="CompareValidator1" runat="server" ControlToValidate="TextBox1" Display="Dynamic" ErrorMessage="Invalid Date" Operator="DataTypeCheck" Type="Date"> </asp:CompareValidator> <cc1:ValidatorCalloutExtender ID="CompareValidator1_ValidatorCalloutExtender" runat="server" Enabled="True" TargetControlID="CompareValidator1"> </cc1:ValidatorCalloutExtender> Adding RangeValidator – We will restrict the user to select a date range starting from today to 15 days from now. <asp:RangeValidator ID="RangeValidator1" runat="server" ControlToValidate="TextBox1" ErrorMessage="RangeValidator" Type="Date"> </asp:RangeValidator> <cc1:ValidatorCalloutExtender ID="RangeValidator1_ValidatorCalloutExtender" runat="server" Enabled="True" TargetControlID="RangeValidator1"> </cc1:ValidatorCalloutExtender>
In the code behind your page, add this C # code
protected void Page_Load(object sender, EventArgs e) { RangeValidator1.MinimumValue = System.DateTime.Now.ToShortDateString(); RangeValidator1.MaximumValue = System.DateTime.Now.AddDays(15).ToShortDateString(); }
Vb.net
Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) RangeValidator1.MinimumValue = System.DateTime.Now.ToShortDateString() RangeValidator1.MaximumValue = System.DateTime.Now.AddDays(15).ToShortDateString() End Sub
Well, these were some tips related to CalendarExtender . As future versions of the toolkit are released, we should hope that simpler ways to achieve this functionality will be available.
From : http://www.dotnetcurry.com/ShowArticle.aspx?ID=149
Another advanced approach is to extend the CalendarExtender JavaScript block, but then you have your own version of ajax toolkit.
http://codegoeshere.blogspot.com/2007/06/extending-calendarextender.html