I have been trying to make jquery datepicker plugin work on a content page but have been unable to make the page execute any jquery at all. I managed to get the datepicker working on my masterpage but not the content page. Also the firebug tool for firefox didnt pick up any javascript errors. If anyone has a solution for making the datepicker work on my content page that would be great. Thanks in advance.
.ASPX:
<asp:Content ID="HeaderContent" runat="server" ContentPlaceHolderID="HeadContent">
<script type="text/javascript">
$(document).ready(function () {
$("#TextBoxConnectedOn").datepicker();
});
</script>
</asp:Content>
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
<input type="text" name="TextBoxConnectedOn" id="TextBoxConnectedOn"
runat="server" MaxLength="10"/>
</asp:Content>
Masterpage head:
<head runat="server">
<link type="text/css" href="pages/scripts/themes/ui-darkness/jquery.ui.all.css"
rel="stylesheet" />
<script type="text/javascript" src="scripts/jquery-1.4.2.js"></script>
<script type="text/javascript" src="scripts/ui/jquery.ui.core.min.js"></script>
<script type="text/javascript" src="scripts/ui/jquery.ui.datepicker.min.js"></script>
<asp:ContentPlaceHolder ID="HeadContent" runat="server">
</asp:ContentPlaceHolder>
</head>
EDIT
I changed “#TextBoxConnectedOn” to “#<%= TextBoxConnectedOn.ClientID %>” and now firebug shows that its loading the needed pictures once i click on the input but still it doesnt show the datepicker. My question topic and main source of frustration was the jquery not executing though so I suppose this post is answered, thanks for all the info, Ill see if i can find out why it doesnt display
As a server-generated control the
idof the input box won’t actually beTextBoxConnectedOn; ASP.NET will have generated anidfor you. View the source of the page in your browser to verify this.You have two choices:
Remove the
runat="server"attribute from the control, to make it a regular HTML element (does it really need to be server generated?), orReference the correct
idLike this:
EDIT
As per @jbn’s comment below, as of ASP.NET 4 you can tell server controls to use static IDs by setting their
ClientIDModetoStatic.