Click here to Skip to main content
15,878,048 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
i am using Ajax calendar extender in my asp.net site,
I want a calender in which user should select either of two dates like 1).CurentDAte or 2)one Previous date before current date ..
in following code ..i am able to select only current date ,but cant select one previos date before current date...

JavaScript
function checkDate1(sender, args) {
       var toDate= new Date();
           toDate.setMinutes(0);
           toDate.setSeconds(0);
           toDate.setHours(0);
           toDate.setMilliseconds(0);
           if (sender._selectedDate < toDate) {
               alert("You cannot select a day earlier than today!");
               sender._selectedDate = new Date();
               // set the date back to the current date
               sender._textbox.set_Value(sender._selectedDate.format(sender._format))
           }
if (sender._selectedDate > new Date()) {
               alert("You cannot select a day greater than today!");
               sender._selectedDate = new Date();
               // set the date back to the current date
               sender._textbox.set_Value(sender._selectedDate.format(sender._format))
           }
       }
Posted
Updated 26-Jan-14 22:13pm
v2

1 solution

You could always set the Start and End dates of the calendar when you create the page.

C#
csCalendar.StartDate = DateTime.Now.AddDays(-1);
csCalendar.EndDate = DateTime.Now;


This will restrict the calendar to only allow selection of the current date and the previous date.
 
Share this answer
 
Comments
rahulDer 27-Jan-14 4:41am    
thnq for this reply but my cCalendarExtender does not suuport StartDate or EndDate properties ..
so if it is possible to deal with javascript thaen plz do tell..
hypermellow 27-Jan-14 4:57am    
What version of the Ajax Control Toolkit do you have?

... I'm surprised you don't have StartDate and EndDate properties.

Have a look at the Calendar Properties sectionof this page:
http://www.asp.net/AjaxLibrary/AjaxControlToolkitSampleSite/Calendar/Calendar.aspx

It shows they are available via the aspx code behind, and not javascript.

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