我在报表查看器控件中添加了一个jQuery日期选择器,并成功删除了我的日期参数的时间戳,但出于某种原因,当我点击“查看报表”按钮时,看起来它只是对每个参数进行回发时间而不是运行报告。我相信这是由于我如何删除_endRequest处理程序中的时间戳,但我无法找出任何其他方法来删除时间戳。 当我查看chrome dev工具时,我可以看到console.log消息,它会在我第一次选择日期时删除时间戳并记录我的消息,但是当我点击“查看报告”按钮时,它会两次点击我的console.log消息。当我点击“查看报告”按钮时,是否有可能无法点击_endRequest处理程序,这可能会解决我的问题。也对其他想法持开放态度。下面是我的ReportViewer html页面和用于处理datepicker的jQuery函数。
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<link rel="stylesheet" href="//ajax.googleapis.com/ajax/libs/jqueryui/1.11.2/themes/smoothness/jquery-ui.css" />
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:ScriptManager ID="ScriptMgr" runat="server"></asp:ScriptManager>
<rsweb:ReportViewer ID="ReportViewer" Style="display: table !important; margin: 0px; overflow: auto !important;" runat="server"></rsweb:ReportViewer>
</div>
</form>
<script type="text/javascript" src="http://ajax.microsoft.com/ajax/jquery/jquery-2.1.1.js"></script>
<script src="//ajax.googleapis.com/ajax/libs/jqueryui/1.11.2/jquery-ui.min.js"></script>
<script src="http://code.jquery.com/jquery-1.8.2.js"></script>
<script src="http://code.jquery.com/ui/1.9.1/jquery-ui.js"></script>
<script type="text/javascript">
$(function () {
$('div').add('td').attr('onclick', '');
$('input').removeAttr('disabled');
showDatePicker();
// added so that datepicker reappears each time on textbox click and postback
Sys.WebForms.PageRequestManager.getInstance().add_endRequest(applicationInitHandler);
function applicationInitHandler() {
showDatePicker();
console.log("here");
var fromDate = document.getElementById("ReportViewer_ctl04_ctl05_txtValue").value;
var toDate = document.getElementById("ReportViewer_ctl04_ctl03_txtValue").value
console.log(toDate);
console.log(fromDate);
document.getElementById("ReportViewer_ctl04_ctl05_txtValue").value = fromDate.substring(0, 10);
document.getElementById("ReportViewer_ctl04_ctl03_txtValue").value = toDate.substring(0, 10);
}
function showDatePicker() {
var parameterRow = $("#ParametersRowReportViewer");
var innerTable = $(parameterRow).find("table").find("table");
var span = innerTable.find("span:contains('Date')");
if (span.length) {
var innerRow = $(span).parents('tr').eq(0);
var innerCell = innerRow.find('td').eq(1);
var textFrom = innerCell.find('input[type="text"]');
innerCell = innerRow.find('td').eq(4);
var textTo = innerCell.find('input[type="text"]');
$(textFrom).datepicker({
dateFormat: 'mm/dd/yy',
changeMonth: true,
changeYear: true,
numberOfYears: 1,
numberOfMonths: 1,
onClose: function (selectedDate) {
$(textTo).datepicker("option", "minDate", selectedDate);
}
});
$(textFrom).focus(function (e) {
e.preventDefault();
$(textFrom).datepicker("show");
});
$(textTo).datepicker({
dateFormat: 'mm/dd/yy',
changeMonth: true,
changeYear: true,
numberOfYears: 1,
numberOfMonths: 1,
onClose: function (selectedDate) {
$(textFrom).datepicker("option", "maxDate", selectedDate);
}
});
$(textTo).focus(function () {
$(textTo).datepicker("show");
});
}
}
});
</script>
</body>
</html>