0

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">
4
  • 1
    Check your browsers error console for any clues. Press F12 in most browsers. Commented Mar 21, 2014 at 14:00
  • @DaveHogan there is no error there Commented Mar 21, 2014 at 14:03
  • Works here jsfiddle.net/J34fS/1 Commented Mar 21, 2014 at 14:11
  • @YuriyGalanter i know it works in other places, but i am asking why it is not working with me. aslo, as the first answer says, the id is differenent, can you help please? Commented Mar 21, 2014 at 14:19

2 Answers 2

1

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();
Sign up to request clarification or add additional context in comments.

Comments

0

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.

4 Comments

the Id in the html is MainContent_datepicker but there is no ClientIDMode in the input, why please?
I'm saying to change the tag to: <input type="text" id="datepicker" ClientIDMode="Static" runat="server">
Yuriy made a good point below. In addition to what he said, you can also do $('<%= datepicker.ClientID %>').datepicker(); which will insert the proper ID into your javascript. The ClientID could change if the structure of your page changes. If that happens, the ID that this inserts will change with it.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.