I'm really struggling to get the jQuery datepicker working in ASP.NET. I've tried various examples, but nothing seems to work for me. Even though I'm fairly new to ASP.NET, I am learning quickly!
Here is the script I am trying to use:
<script>
$(document).ready(function () {
$(function () {
$("#" + '<%=txtDOB.ClientID%>').datepicker();
});
});
</script>
The control on my aspx page looks like this:
<asp:TextBox ID="txtDOB" CssClass="form-control" runat="server"></asp:TextBox>
However, as soon as I close the server tag %>
, a red line appears underneath the txtDOB control with an error message:
txtDOB is not declared. It may be inaccessible due to its protection level.
I have already made sure that the class is public in the code behind and tried moving the script to the bottom of the page. Interestingly, if I change the asp textbox to an HTML input, it works perfectly fine.