user755230
user755230

Reputation: 125

how to implement datepicker in asp.net using jquery?

    <script src="<%=("../Scripts/jquery-1.6.1.min.js") %>" type="text/javascript" />
   <script src="<%=("../Scripts/jquery-datePicker.js") %>" type="text/javascript" />

<script type="text/javascript">

    $(function() {

     $("#txtDate").datepicker();       

    });   

   </script>

I have used this code but it doesnot show me the popup calender on click on textbox. what can be the problem. it doesnot give any error.

Upvotes: 0

Views: 7506

Answers (3)

Govind Malviya
Govind Malviya

Reputation: 13743

why not set path directly? and close script tag with this </script>

<script src="../Scripts/jquery-1.6.1.min.js" type="text/javascript" ></script>
<script src="../Scripts/jquery-datePicker.js" type="text/javascript" ></script>

Use ClientID for server control

<script type="text/javascript">

    $(function() {

     $("#<%= txtDate.ClientID %>").datepicker();       

    });   

   </script>

you can also use ready function

<script type="text/javascript">
$(document).ready(function() {
 $("#<%= txtDate.ClientID %>").datepicker();       
});
</script>

if ID selector doesn't work then use class selector it is good for ASP.NET server control

<asp:TextBox ruat="server" ID="txtDate" CssClass="DateField"></asp:TextBox>

<script type="text/javascript">
    $(document).ready(function() {
     $(".DateField").datepicker();       
    });
    </script>

Upvotes: 0

Krishna Kumar N
Krishna Kumar N

Reputation: 137

ID of ASP.NET server control is different than that of the normal HTML ID. So if you are using a Server control, then run your code, open the page source, get the ID that is displayed in the page source and use this ID instead of txtDate.

Also use

$(document).ready(function() { $("#<id>").datepicker(); });

Upvotes: 0

Dutch Nico
Dutch Nico

Reputation: 270

Perhaps you should use the document.ready function

$(document).ready(function() {
 $("#txtDate").datepicker();       
});

Upvotes: 1

Related Questions