简体   繁体   中英

jQuery DatePicker - Populate date value from code behind not working

I have a textbox on which I'm using jQuery DatePicker. It works fine when the textbox has no value. I have a button on whose click I'm populating this textbox with a datevalue. Then, if I click on the textbox the datepicker does not appear. I tried populating the date in both the formats.

<script>
$(function () {
    $('#InputNamesBirthday').datepicker({
        changeMonth: true,
        changeYear: true,
        dateFormat: "dd-mm-yy",
        defaultDate:null,
        altFormat: "yy-mm-dd"
    });
});
 </script>


birthDate = Convert.ToDateTime(dataReaderNames["BORN"]);
InputNamesBirthday.Text = birthDate.ToString("yyyy-MM-dd", CultureInfo.CreateSpecificCulture("en-US"));

Thanks, Dev

the problem is most likely the jquery selector. this is a common problem with webforms. the Server ID rarely matches the Client ID. this is because webforms auto-generates IDs based on the containers a control is nested in. fore example a text box in a repeater, in a user control, on a page, with a master page will produce a client id something like this.

master$usercontrol$repeater$0$textbox

the cleanest way to solve this is to use a class selector to access the element, rather than an ID.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM