tags:

views:

195

answers:

3

Hello friends!!!

I have used jquery datepicker in my .aspx page. The control is working fine. What i need is to disable the control if the textbox on which it is linked is disabled. For ex. I am showing datepicker on textbox "txtDateOfAssignment". If the Enabled property of this textbox is false then datepicker should not be active on that.

Anybody have an idea?

Thanks in advance.

+2  A: 

if you look at the documentation you'll notice that there is a "disable" method, so you can do :

$('id-of-your-textbox').datepicker('disable');

Ok, finally you're not using jquery-UI but jquery-datepicker, so it should be more something like as referred to the documentation here

$(document).ready(function () {
  $('.date-picker').dpSetDisabled(true);
});

If you want to disable only 1 datepicker dont use the class selector ".date-picker" but the id of the datepicker you want to disable.

Mike
Thanks Mike! But i am not using UI datepicker. The above code is not working for me.
IrfanRaza
hmm ok so which one are you using ?
Mike
Please look at this link http://www.kelvinluck.com/assets/jquery/datePicker/v2/demo/index.html. There is also demo on disabling datepicker (http://www.kelvinluck.com/assets/jquery/datePicker/v2/demo/datePickerDisabled.html), but i am unable to implement it on Page_Load event of my aspx page. There are date fields in my aspx page, some of which need to be disabled while page is being displayed.Thanks for sharing your valuable time.
IrfanRaza
I dont't know aspx but did you wait for the DOM being ready .. as the example I just added
Mike
A: 

Another possible Solution is var j$=jQuery.noConflict(); j$("#inputTextID").datepicker(('disable' ));

j$("#inputTextID").datepicker(('enable' ));

Rajeeev
A: 

To enable, disable, remove, attach dynamically or conditionally then read this. http://praveenbattula.blogspot.com/2009/11/how-to-jquery-datepicker-enable-disable.html

In the logic where you are disabling the textbox, call the disable property in the above example and it works fine.

Rare Solutions