0

I have looked all over to solve this issue and all suggestions I have received have not worked. This is what I'm importing:

<link href="css/jquery-ui-1.8.12.custom.css" rel="stylesheet" type="text/css" />
<script src="js/jquery-1.5.1.js" type="text/javascript"></script>
<script src="js/jquery.ui.widget.min.js" type="text/javascript"></script>
<script src="js/jquery-ui-1.8.12.custom.min.js" type="text/javascript"></script>
<script src="js/jquery.ui.datepicker.min.js" type="text/javascript"></script>  

This is the Jquery and text box

<script type="text/javascript">
   $(function () {
      $('#EarliestArrivalTB').datepicker();
   });
</script>
<asp:TextBox ID="EarliestArrivalTB" runat="server"></asp:TextBox>

I got it working on my localhost but when i moved it over to the web server, it does not work. What am i doing wrong here?

3
  • I have done this so far <script type="text/javascript"> $(function () { $('#<%=EarliestArrivalTB.ClientID %>').datepicker(); }); </script> This has no worked either. I thank you all so far for your help. But I have tried these already. Commented May 10, 2011 at 19:17
  • are your script files downloaded correct? Commented May 10, 2011 at 19:28
  • I believe so. I got them downloaded straight from the Jquery site. The files worked on my local machine but not on the server so im assuming they are fine. Commented May 10, 2011 at 19:43

3 Answers 3

3

The problem is you're referencing a server-side ID. You need to generate the client-side ID for the asp.net control for it to work:

<script type="text/javascript">
   $(document).ready(function() {
      $('#<%=EarliestArrivalTB.ClientID %>').datepicker();
   });
</script>

#EarliestArrivalTB as a selector on the client doesn't exist because it's clientside representation will be very different.

Sign up to request clarification or add additional context in comments.

Comments

2

My favourite way of doing it

<script type="text/javascript">
   $(function () {
      $('.DatePicker').datepicker();
   });
</script>
<asp:TextBox ID="EarliestArrivalTB" runat="server" CssClass="DatePicker"></asp:TextBox>

This means implementing the datapicker on any field is no more complicated that adding a DatePicker class.

Edit: I suppose I should tell you why its not working too. The Id you specify on a server control is the Id you use to reference in server side code. Once its put on the page because of naming containers and such its client Id will be different to make sure there are no naming conflicts, as a result there is the ClientID property so you can discover what that client side Id actually is.

7 Comments

I tried that class thing before to no success. I tried again and failed. I understand the issue and I even used the rendered id that came from the web page and still doesn't work. Thank you for the input though
Is this all browsers? What other libraries are you using? Have you looked at the javascript console to check for errors?
All browsers, Im not using any other libraries on this page. The only errors im getting is "Object doesnt support this property or method" and points to line 295 which is this line: $(function () {
Thats strange. Ok, how about changing it to this jQuery(document).ready(function() {
Sorry i cant format the code in the comments but this is what i have: $(document).ready(function() { $('#<%=EarliestArrivalTB.ClientID %>').datepicker(); }); This still didnt work and I think you understand now why this is baffling me. lol
|
0

try

<script type="text/javascript">
   $(function () {
      $('#<%=EarliestArrivalTB.ClientID %>').datepicker();
   });
</script>

3 Comments

<script type="text/javascript"> $(function () { $('<%=EarliestArrivalTB.ClientID %>').datepicker(); }); I tried your idea and didn't work. Thank you for your suggestion though. </script>
Also tried the edited version and is pulling the correct ID but the Jquery is still not working.
see if you can download the script from your web server by doing http://mysite/js/jquery-1.5.1.js

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.