views:

215

answers:

2

i am working on asp.net using C# and using jquery datepicker

my question is, how can i disable dates which are federal holidays?

i have a dynamic dates which comes from sql server.

anybody have done something similar or any idea how can i achieve this?

$(document).ready(function () {       
  $('#endDate').datepicker({ showOn: 'button',  
      buttonImage: '../images/Calendar.png',  
      buttonImageOnly: true, onSelect: function () { },  
      onClose: function () { $(this).focus(); }  
    });  

  $('#startDate').datepicker({ showOn: 'button',  
      buttonImage: '../images/Calendar.png',  
      buttonImageOnly: true, onSelect:  
        function (dateText, inst) {  
          $('#endDate').datepicker("option", 'minDate', new Date(dateText));  
        }  
      ,  
      onClose: function () { $(this).focus(); }  
    });  
}); 

Thanks.

+1  A: 

You might want to look at a different plugin, this one supports bank holidays, so starting from that example, you can probably do what you want to do:

http://www.kelvinluck.com/assets/jquery/datePicker/v2/demo/

SeanJA
+1 for suggesting my date picker :) There is already an example showing how you can set up start/ end dates:http://www.kelvinluck.com/assets/jquery/datePicker/v2/demo/datePickerStartEnd.htmlAnd there are also examples of using a renderCallback to control the behaviour of each date. This one disabled weekends:http://www.kelvinluck.com/assets/jquery/datePicker/v2/demo/datePickerCustomCellRender.htmlAnd this complex example shows dynamicly changing date rules:http://www.kelvinluck.com/assets/jquery/datePicker/v2/demo/datePickerLimitAvailableDatesAjax2.html
vitch
@vitch < shameless plug > Seriously though, it is a great versatile plugin.
SeanJA
A shameless plug indeed... But since you'd mentioned it :) Thanks!
vitch
or at least i can have alert if the user clicks on holidays? instead of disabling?
Abu Hamzah
@vitch: do you have sample codethat demonstrates how you can load the date picker via ajax in asp.net?
Abu Hamzah
Yes - you can do what you like when the user clicks on a day... There are lots of different examples which show the different functionality. This one uses a renderCallback to alert when certain days are clicked on: http://www.kelvinluck.com/assets/jquery/datePicker/v2/demo/renderCalendarCallback.htmlRe. loading it via ajax in asp.net, you might be better to start another question with more information clarifying exactly what you are asking...
vitch
+2  A: 
         // April 30,2010 and May 1, 2010 are disabled
var disabledDates = ['04/30/2010', '05/01/2010'];

$(function(){

    $('#datepicker').datepicker({

        dateFormat: 'dd/mm/yy',
        beforeShowDay: editDays
    });

    function editDays(date) {
        for (var i = 0; i < disabledDates.length; i++) {
            if (new Date(disabledDates[i]).toString() == date.toString()) {             
                 return [false];
            }
        }
        return [true];
     }   

});

demo

Reigel
looks what i want :) let me try it and get back to you
Abu Hamzah