Van*_*dze 9 asp.net ajax jquery jquery-ui asp.net-ajax
我正在尝试使用UpdatePanel控件和Jquery UI进行日期选择器.但是如果日期选择器控件(TextBox)在UpdatePanel的ContentTemplate中,则日期选择器不起作用.
这是代码:
<script src="Scripts/jquery-1.4.1.js" type="text/javascript"></script>
<script src="Scripts/jqueryui/js/jquery-ui-1.8.8.custom.min.js" type="text/javascript"></script>
<script language="javascript" type="text/javascript">
$(function () {
var dates = $(" #txtDatePicker").datepicker(
{
firstDay: 1,
maxDate: '-1y',
minDate: '-1y',
dateFormat: 'dd/mm/yy',
changeMonth: true,
changeYear: true,
showAnim: "drop",
onSelect: function (selectedDate) {
var option = this.id == "txtDatePicker" ? "minDate" : "maxDate",
instance = $(this).data("datepicker");
date = $.datepicker.parseDate(
instance.settings.dateFormat ||
$.datepicker._defaults.dateFormat,
selectedDate, instance.settings);
dates.not(this).datepicker("option", option, date);
}
}
);
});
</script>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:TextBox ID="txtDatePicker" runat="server"></asp:TextBox>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="btnSomeButton" EventName="Click" />
</Triggers>
</asp:UpdatePanel>
Run Code Online (Sandbox Code Playgroud)
有没有办法在UpdatePanel内容中使用JQuery UI datepicker?
然后你将控件放入面板中,它们可以更改它们的唯一 ID。尝试一下你的代码:
var dates = $("#<%= txtDatePicker.ClientID %>").datepicker(
Run Code Online (Sandbox Code Playgroud)
或将您的代码移至
$(document).ready(function() {
// Handler for .ready() called.
});
Run Code Online (Sandbox Code Playgroud)
选择器中还有一个空格:
var dates = $(" #txtDatePicker").datepicker(
Run Code Online (Sandbox Code Playgroud)
代替:
var dates = $("#txtDatePicker").datepicker(
Run Code Online (Sandbox Code Playgroud)
然后使用 UpdatePanel 和 AJAX 工具包,您应该在期间使用初始化程序
function pageLoad()
{ // MS AJAX - UpdatePanel initialize
InitializeDatePicker();
}
Run Code Online (Sandbox Code Playgroud)
对于 UpdatePanel 中的控件,以及在
$(document).ready(function() { // jQuery
AssignFrameHeight();
});
Run Code Online (Sandbox Code Playgroud)
对于 UpdatePanel 之外的 jquery 控件。
| 归档时间: |
|
| 查看次数: |
13287 次 |
| 最近记录: |