1

I am trying to display the javascript date time picker in a textbox on the content page, that is derived from the master page, but the datetime picker is not getting displayed.
This is my content page:

<link rel="stylesheet" href="Datepicker.css">
<script src="https://code.jquery.com/jquery.js"></script>
<script src="Datepicker.js"></script>
<script>
$(document).ready(function() {
    $('#dp').datepicker();
});
</script>
<script>
$(document).ready(function() {
    $('#dp1').datepicker();
});
</script>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
<asp:Label ID="Label1" runat="server" Text="From"></asp:Label>&nbsp;
    <input id="dp" type="text" runat="server"/>&nbsp;
    <asp:Label ID="Label2" runat="server" Text="To"></asp:Label>&nbsp;
    <input id="dp1" type="text" runat="server" />&nbsp;
    <asp:Button ID="Button1" runat="server" Text="Search" onclick="Button1_Click" />
<asp:GridView ID="gvdetails" runat="server">
</asp:GridView>
</asp:Content>

Note: This works without the master page,but when I add it in a content page,it does not work.Please help

2 Answers 2

2

When ASP is served through IIS, all the runat="server" elements are given a unique name.

In order to find this name use the <%= %> syntax with the ClientID of your object. In your case it would be:

$('#<%=dp1.ClientID%>').datepicker();

Alternatively, you could set your element to use static names.

<input id="dp1" type="text" runat="server" ClientIDMode="Static" />

(but dont do both)

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

Comments

0

something out of the box.

Make it simple mate - use DateTime from Html5

<form>
  Birthday (date and time):
  <input type="datetime" name="bdaytime">
</form>

Comments

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.