JQuery Datepicker Throws Runtime Error

November 5, 2012 2:20 pm
Andri Kasta Marengga

JQuery Datepicker Throws Runtime Error

I use JQueryUI Datepicker as my datepicker on ASP Net webform. It run smoothly until I added some field validator to my form. Whenever I click on date picker calendar icon it throws this error

Microsoft JScript runtime error: ‘length’ is null or not an object

On this line of codes

var i;
for (i = 0; i < vals.length; i++) {
     ValidatorValidate(vals[i], null, event);
}
ValidatorUpdateIsValid();

The reason why its breaking because of the onselect function of the datepicker causes validators to be fired automatically. To resolve this error we have to change function calling datepicker, from this:

<script type="text/javascript">
    $(function() {
        $(document.getElementById('<%= txtMyDate.ClientID %>')).datepicker({
            changeMonth: true,
            changeYear: true,
            showOn: 'button',
            buttonImage: 'script/JQuery/themes/calendar.gif',
            buttonImageOnly: true,
            dateFormat: 'mm-dd-yy'
        });
    });
</script>

To this one:

<script type="text/javascript">
    $(function() {
        $(document.getElementById('<%= txtMyDate.ClientID %>')).datepicker({
            changeMonth: true,
            changeYear: true,
            showOn: 'button',
            buttonImage: 'script/JQuery/themes/calendar.gif',
            buttonImageOnly: true,
            dateFormat: 'mm-dd-yy',
            onSelect: function(){}
        });
    });
</script>

, , ,

No comments yet.

Leave a Reply