Click here to Skip to main content
15,881,204 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am trying to use bootstrap datepicker with asp.net textbox but it gives an error

VB
TypeError: dp.datepicker is not a function


language: "tr"


Here is my code

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



XML
<div class="form-group col-md-5">
                                            <label for="exampleInputPassword1">Date : </label>
                                            <asp:TextBox ID="txt_date" runat="server"  type="date"
                                            CssClass='form-control' placeholder="YYYY-MM-DD" ClientIDMode="Static"></asp:TextBox>
                                        </div>


Thanks in advance for your answers
Posted
Updated 28-Jul-14 0:04am
v2
Comments
Kornfeld Eliyahu Peter 28-Jul-14 7:20am    
On which line?
Omkar Hendre 28-Jul-14 7:28am    
It gives me the error for this line

language: "tr"


if i remove this line then it gives me error for a date format
Kornfeld Eliyahu Peter 28-Jul-14 7:32am    
It seems you missed to include the js file for bootstrap's datepicker...
Something like <script src="js/bootstrap-datepicker.js" />
Omkar Hendre 28-Jul-14 7:41am    
i include those required file but still it gives me the error
Kornfeld Eliyahu Peter 28-Jul-14 7:48am    
Order of script blocks?

I think your jQuery is not loaded properly. Try adding a reference of jQuery to your page.
Checklists:
1. Put the reference of jQuery before closing body tag.
2. Don't load the same script twice.
3. Check the order of your JS references. First put reference for jQuery then other script files.

Hope it helps!
   --Amy
 
Share this answer
 
Comments
Omkar Hendre 29-Jul-14 6:02am    
thank you sir actully i solve my problem as you said i load the js file twice
_Amy 31-Jul-14 7:36am    
Good. :)
Karthik_Mahalingam 28-Apr-15 14:16pm    
good answer
Your error clearly says that your dp.datepicker function is not available and you are trying to use it. Only cause of this kind of issue is you are not including the reference of bootstrap-datepicker.js file. Apart from that you need to use Jquery and bootstrap plugin too.
And the order of reference of these file should be in correct manner :
HTML
 <!-- Jquery -->
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.js"></script>

 <!-- Latest compiled and minified CSS -->
    <link rel="stylesheet" href="//netdna.bootstrapcdn.com/bootstrap/3.0.2/css/bootstrap.min.css" />

    <!-- Optional theme -->
    <link rel="stylesheet" href="//netdna.bootstrapcdn.com/bootstrap/3.0.2/css/bootstrap-theme.min.css" />

    <!-- Latest compiled and minified JavaScript -->
    <script src="//netdna.bootstrapcdn.com/bootstrap/3.0.2/js/bootstrap.min.js"></script>
    
    <link rel="stylesheet" href="css/datepicker.css" type="text/css" />


    <script src="Scripts/bootstrap-datepicker.js" type="text/javascript"></script>


Reference : Click here[^]


Good luck.
 
Share this answer
 
Comments
Omkar Hendre 29-Jul-14 6:03am    
Thank You Sir Thank You very much for your such a good reply
Raje_ 29-Jul-14 6:42am    
Cheers!
Omkar Hendre 29-Jul-14 6:08am    
Sir sorry to giving trouble you but if you know the link to how to do the bootstrap validation operations in asp.net c# then please tell me
and again thanks in advance.
Raje_ 29-Jul-14 6:43am    
Omkar Hendre 29-Jul-14 6:44am    
Thank You Sir
Let me check it first then i will tell you whether it is working or not

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900