Click here to Skip to main content
15,883,901 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi,

Situation : I have two dates, FromDate and ToDate, when I select FromDate at that time I want past dates in ToDate(past means less than that date which is selected in FromDate)be disabled.and I have my min date and max date in both the asp ajax calender extender. So can any one have that idea how to do it?



Thanks
Posted

1 solution

Hi,

Following code explains how I'm using custom jQuery functions to enable only Sunday and Saturday respectively as AllowFrom and AllowTo


C#
///Restricts the From Date Calendar Extender
function AllowFrom(sender, args) {
           $('div[id$="caltxtFrom_container"] div[class="ajax__calendar_day"]').each(function () {
               var date = new Date();
               date = $(this).attr('date');
               if (date.getDay() != 0)
                   $(this).css('cursor', 'pointer').attr('disabled', 'disabled').css('text-decoration', 'line-through');
               else
                   $(this).css('font-weight', 'bold');
           });

       }

       //Restricts the To Date Calendar Extender
       function AllowTo(sender, args) {
           $('div[id$="caltxtToDate_container"] div[class="ajax__calendar_day"]').each(function () {
               var date = new Date();
               date = $(this).attr('date');
               if (date.getDay() == 6)
                   $(this).css('font-weight', 'bold');
               else
                   $(this).css('cursor', 'pointer').attr('disabled', 'disabled').css('text-decoration', 'line-through');
           });

       }


and here are my calendar extender controls. Please note that I'm calling above function on OnClientShown.

VB
<ajaxToolkit:CalendarExtender ID="caltxtFrom" runat="server" Format="MM/dd/yyyy"
                                                       OnClientShown="AllowFrom" PopupPosition="Right" TargetControlID="txtFromDate" />


XML
<ajaxToolkit:CalendarExtender ID="caltxtToDate" runat="server" Format="MM/dd/yyyy"
                                                     OnClientShown="AllowTo" PopupPosition="Right" TargetControlID="txtToDate" />
                                             </td>


jQuery functions mentioned above you can change to match your requirements

Hope that Helps,
Thanks
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900