Reputation: 171
Completely confused as to why this isn't working... The error I receive is:
0x800a01b6 - JavaScript runtime error: Object doesn't support property or method 'datepicker'
Master.master
<head id="head1" runat="server">
<script src="js/jquery-1.10.2.js"></script>
<script src="js/jquery-ui.js"></script>
<script language="javascript">
$(function () {
$("#ctl00_cphMain_txtExpDate").datepicker();
});
</script>
</head>
Page.aspx
<asp:TextBox ID="txtExpDate" runat="server" Visible="true" ReadOnly="false"></asp:TextBox>
When the page loads, I immediately get the JavaScript error. But when I view source, everything looks fine:
View Source, from browser
<input name="ctl00$cphMain$txtExpDate" type="text" id="ctl00_cphMain_txtExpDate" />
It runs without error in JSFiddle and even shows the picker popup. What is causing the error? This is a C# ASP.NET web application.
JSFiddle - http://jsfiddle.net/ncojuu21/
Upvotes: 0
Views: 670
Reputation: 171
This error was caused my MasterPage having duplicate jQuery references. Issue was resolved when one reference was removed and now the .datepicker() is working perfectly.
Upvotes: 0
Reputation: 1235
You have to call the script with <script type="text/javascript">
instead of <script type="javascript">
.
Replace $("#ctl00_cphMain_txtExpDate")
by $("#<%=txtExpDate.ClientID%>")
Upvotes: 1