简体   繁体   中英

how to use datepicker in aspx page?

I am using the following code in an ASPX page for a date picker:

 <asp:Content ID="HeaderContent" runat="server" ContentPlaceHolderID="HeadContent"> 

    <link rel="stylesheet" href="http://code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css" />
    <script src="http://code.jquery.com/jquery-1.9.1.js"></script>
    <script src="http://code.jquery.com/ui/1.10.3/jquery-ui.js"></script>

<title></title>
<script type="text/javascript">
    $(function () {           
        $("#txtToDate").datepicker({ dateFormat: "dd/mm/yy" }).val();
    });

</script>

  </asp:Content>

  <asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent">

    <asp:Label ID="Label33" runat="server" Font-Bold="True" ForeColor="Black" 
        Text="To Date"></asp:Label>
    <input id="txtToDate" runat="server" 
onblur="if(this.value == '') { this.value='dd/mm/yyyy'}" 
onfocus="if (this.value=='dd/mm/yyyy') {this.value=''}" type="text" 
value="dd/mm/yyyy" />

Using the same code in an html page it is working with the same browser. with the aspx page this code is not working.

Can anyone tell me what changes i need to make to this code?.

Replace your Javascript with this.

 <script language="javascript" type="text/javascript">
    $(document).ready(function () {
        $("#<%= txtToDate.ClientID %>").datepicker({ dateFormat: "dd/mm/yy" }).val();
    });
</script>  
The above code is working for me. Please check it my code below


<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <link rel="stylesheet" href="http://code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css" />
    <script src="http://code.jquery.com/jquery-1.9.1.js"></script>
    <script src="http://code.jquery.com/ui/1.10.3/jquery-ui.js"></script>

    <script type="text/javascript">
        $(function () {
            $("#txtToDate").datepicker({ dateFormat: "dd/mm/yy" }).val();
        });

    </script>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:Label ID="Label33" runat="server" Font-Bold="True" ForeColor="Black" Text="To Date"></asp:Label>
        <input id="txtToDate" runat="server" onblur="if(this.value == '') { this.value='dd/mm/yyyy'}"
            onfocus="if (this.value=='dd/mm/yyyy') {this.value=''}" type="text" value="dd/mm/yyyy" />
    </div>
    </form>
</body>
</html>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM