How to use Boostrap DateTimePicker in ASP.Net Web Form

假装没事ソ 提交于 2020-03-05 05:53:06

问题


I am trying to use a Bootstrap datetimepicker in my Asp.Net web form. No errors are being thrown but the calendar never fires when I click on the icon. How can I get this to work in Asp.Net? Since this is not an asp: control, I'm not making an _onClick() function in my C#, but do I need to make one in my <script></script? Here's what my code looks like:

<link href="http://ajax.aspnetcdn.com/ajax/jquery.ui/1.9.1/themes/start/jquery-ui.css" rel="stylesheet" type="text/css" />
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.0/css/bootstrap.min.css">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.0/css/bootstrap-theme.min.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datetimepicker/4.17.37/css/bootstrap-datetimepicker.min.css" />
...
<script src="https://code.jquery.com/jquery-1.9.1.js"></script>
<script src="https://code.jquery.com/ui/1.9.1/jquery-ui.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.0/js/bootstrap.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.10.6/moment.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datetimepicker/4.17.37/js/bootstrap-datetimepicker.min.js"></script>
<script type="text/javascript">
     $(document).ready(function() {
        $(function() {
            $('#uxDateTimeLocalTextbox').datetimepicker();
        });
    });
</script>
<body>
....
    <div class="container">
      <div class='col-md-5'>
        <div class="form-group">
          <div class='input-group date' >
            <input type='text' class="form-control" id="uxDateTimeLocalTextbox" value="" runat="server"/>
            <span class="input-group-addon">
              <span class="glyphicon glyphicon-calendar"></span>
            </span>
          </div>
      </div>
    </div>
  </div>
</body>

回答1:


set the ClientIDMode to "Static"

<input type='text' class="form-control" id="uxDateTimeLocalTextbox" value="" runat="server" ClientIDMode="Static" />

by default webforms change the rendered html id. clientidmode changes that behavior.




回答2:


Please try this code    
<div class="row">
     <label class="col-md-4 control-label">  From Date</label>
 <div class='input-group ' id='FromDate' data-date-format="dd-mm-yyyy"  style="width: 132px;">
  <input type='text' class="form-control" id="txtFromDate"  onchange="txtFromDate_change();" />
   <span class="input-group-addon"><span class="fa fa-calendar fa_cal"></span></span>
   </div>
</div>

<script type="text/javascript">
   $(document).ready(function(){
    $("#FromDate").datepicker({
      autoclose: true,
      todayHighlight: true,
      orientation: 'auto bottom'
     }); 
});
</script>


来源:https://stackoverflow.com/questions/55226181/how-to-use-boostrap-datetimepicker-in-asp-net-web-form

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!