我的page.aspx中有一个更新面板,在更新面板中我有带bootstrap timepicker的文本框,我给出了一个示例:
<asp:UpdatePanel runat="server" id="upd1">
<ContentTemplate>
<div class="form-group">
<div class="row col-md-12 col-md-offset-0">
<label class="control-label">Monday</label>
</div>
</div>
<div class="form-group col-md-3">
<div class="input-group bootstrap-timepicker timepicker input-sm">
<asp:TextBox runat="server" ID="txtFecIni_1" class="form-control input-small "></asp:TextBox>
<span class="input-group-addon "><i class="fa fa-clock-o"></i></span>
</div>
</div>
<div class="form-group col-md-3">
<div class="input-group bootstrap-timepicker timepicker input-sm">
<asp:TextBox runat="server" ID="txtFecFin_1" class="form-control input-small "></asp:TextBox>
<span class="input-group-addon "><i class="fa fa-clock-o"></i></span>
</div>
</div>
</ContentTemplate>
</asp:UpdatePanel>
在我的页面</ form>
下,我添加了这个javascript代码:
<script type="text/javascript">
window.onload = function () {
$('#txtFecIni_1').timepicker({
minuteStep: 30,
defaultTime: false,
showMeridian: false
});
$('#txtFecFin_1').timepicker({
minuteStep: 30,
defaultTime: false,
showMeridian: false
});
}
</script>
<script src="js/jquery-2.2.2.min.js"></script>
<script src="js/bootstrap.min.js"></script>
<script src="js/bootstrap-timepicker.js"></script>
timepicker正常工作,直到对象被抛出autopostback。我怎么解决这个问题? 感谢。
答案 0 :(得分:1)
我以这种方式解决了我的问题:
我为window.onload = function ()
更改function pageLoad()
那样:
之前:
<script type="text/javascript">
window.onload = function () {
$('#txtFecIni_1').timepicker({
minuteStep: 30,
defaultTime: false,
showMeridian: false
});
$('#txtFecFin_1').timepicker({
minuteStep: 30,
defaultTime: false,
showMeridian: false
});
}
</script>
<强>后:强>
<script type="text/javascript">
function pageLoad() {
$('#txtFecIni_1').timepicker({
minuteStep: 30,
defaultTime: false,
showMeridian: false
});
$('#txtFecFin_1').timepicker({
minuteStep: 30,
defaultTime: false,
showMeridian: false
});
}
</script>
我读到每次回发都会调用Pageload。 希望这会对某人有所帮助
答案 1 :(得分:0)
这是由于回发的asp.net控件here is explaination
使用Sys.WebForms.PageRequestManage
你的代码将是这样的......
<script>
jQuery(document).ready(function () {
$('#txtFecIni_1').timepicker({
minuteStep: 30,
defaultTime: false,
showMeridian: false
});
$('#txtFecFin_1').timepicker({
minuteStep: 30,
defaultTime: false,
showMeridian: false
});
});
var prm = Sys.WebForms.PageRequestManager.getInstance();
prm.add_endRequest(function () {
$('#txtFecIni_1').timepicker({
minuteStep: 30,
defaultTime: false,
showMeridian: false
});
$('#txtFecFin_1').timepicker({
minuteStep: 30,
defaultTime: false,
showMeridian: false
});
});
</script>