Bootprap Datepicker with Asp.Net Text Box

It might be a stupid question, but I could not handle my problem. I checked all the questions and answers here, but I did not find a clue. Anyway, I want to use bootstrap datepicker with asp.net textbox. When I use it with an input without the runat = "server" tag, I see that the date picker is displayed, but when I try to use it with a text field with the runat = "server" tag, the date picker is not displayed. Any idea on how to solve this problem?

<asp:TextBox ID="DateTextbox" runat="server" CssClass="m-wrap span12 date form_datetime"></asp:TextBox> <script type="text/javascript"> $(document).ready(function () { var dp = $("#<%=DateTextbox.ClientID%>"); dp.datepicker({ changeMonth: true, changeYear: true, format: "dd.mm.yyyy", language: "tr" }); }); </script> 

Thank you for your responses.

+4
source share
3 answers

thank you for your responses. I made a lil change on my code, which now works. I am sending for future reference.

  <script type="text/javascript"> $(document).ready(function () { var dp = $('#<%=DateTextbox.ClientID%>'); dp.datepicker({ changeMonth: true, changeYear: true, format: "dd.mm.yyyy", language: "tr" }).on('changeDate', function (ev) { $(this).blur(); $(this).datepicker('hide'); }); }); </script> 

but I don’t understand what makes the difference between (") and (')?

+5
source

try it

 <asp:TextBox ID="DateTextbox" ClientIDMode="Static" runat="server" CssClass="m-wrap span12 date form_datetime"></asp:TextBox> <script type="text/javascript"> $(document).ready(function () { var dp = $("#DateTextbox"); dp.datepicker({ changeMonth: true, changeYear: true, format: "dd.mm.yyyy", language: "tr" }); }); </script> 
+1
source

If you are not opposed to simply using the class, you can use the date class in your input, for example:

 <script> $(function () { $('input.date').datepicker({ changeMonth: true, changeYear: true, format: "dd.mm.yyyy", language: "tr" }); }); </script> 

The disadvantage is that you target more elements (potentially), but if you don't have a crazy amount of inputs in your form, this should not make a noticeable difference.

0
source

Source: https://habr.com/ru/post/1497531/


All Articles