Jquery datepicker on asp.net

What is wrong with the code below, its error Compiler error message: CS1002 :; Expected,

$(document).ready(function() { $('<%=StartDate.UniqueID%>').datepicker({ showOn: 'button', buttonImage: '../images/Calendar.png', buttonImageOnly: true, onSelect: function() { }, onClose: function() { $(this).focus(); } }); }); <label for="sd">StartDate:</label> <asp:TextBox ID="StartDate" runat="server"></asp:TextBox> 

Error

 The Controls collection cannot be modified because the control contains code blocks (ie <% ... %>). 
+1
source share
4 answers

The reason I was getting the error:

"Microsoft JScript runtime error: object does not support this property or method"

because I had a link to the .js conflict, and on the page

there were two different .js sets.

Hope this helps others.

+5
source

Perhaps it:

 <div runat="server"> <script type="text/javascript"> $(document).ready(function () { $('#<%=StartDate.ClientID%>').datepicker({ showOn: 'button', buttonImage: '../images/Calendar.png', buttonImageOnly: true, onSelect: function () { }, onClose: function () { $(this).focus(); } }); }); </script> </div> 
+2
source

.js reference conflict (when more than one jquery library link on the same page). If you decide to keep several links (but not the best choice, one link will be better) $ .noConflict (); the method may help in this case (see enter link description here )

 $.noConflict(); jQuery(document).ready(function ($) { $(".dtp").datepicker(); }); 
0
source

This is because on your page you have a link to the jquery library more than once.

For instance:

 <!DOCTYPE html> <html> <head> <title></title> <meta charset="utf-8"> <script type="text/javascript" src="js/jquery.js"></script> <script type="text/javascript" src="js/jquery-ui.js"></script> <script type="text/javascript" language="javascript" > $(function() { $('#datebox').datepicker(); }); </script> </head> <body> <script type="text/javascript" src="js/jquery.js"></script> <input type="text" id="datebox" /> </body> </html> 
-1
source

Source: https://habr.com/ru/post/956055/


All Articles