user3432257
user3432257

Reputation: 415

jQuery UI DatePicker initialisation function not working

This is my code

<script type="text/javascript" src="//code.jquery.com/jquery-1.9.1.js"></script>
    <script type="text/javascript" src="//code.jquery.com/ui/1.10.4/jquery-ui.js"></script>

    <script>
        $(function () {
            $("#tabs").tabs();
        });
        $(function () {
            $("#datepicker").datepicker();
        });

    </script>

but the date function is not working.

it was working on another project, but in this project it is not working.

this is the asp

  <input type="text" id="datepicker" runat="server">

Upvotes: 0

Views: 102

Answers (2)

Yuriy Galanter
Yuriy Galanter

Reputation: 39777

If there's no ClientIDMode among your server-side control's attributes - that means you're using .NET framework < 4.0. In that case either user full client side id of the control in your jQuery code:

$("#MainContent_datepicker").datepicker();

Or do a "ends with" match on the ID:

$('input[id$="datepicker"]').datepicker();

Upvotes: 1

Hypersapien
Hypersapien

Reputation: 623

Unless you specifically tell it not to, ASP.NET will change the id attribute of server aware controls when they are rendered to the browser. Check the HTML source from the browser to see what the ID is actually being set to. You can either use that in your JavaScript code, or you can set ClientIDMode="Static" in the input tag in order to maintain the id that you have chosen (that's the preferred solution). Your other project might have had the ClientIDMode set globally, making it not an issue.

Upvotes: 0

Related Questions