ReportViewer removes date timestamp in _endRequest handler
I have added a jQuery date token to my report viewer and am successfully removing the date stamp form with date parameters, but for some reason when I click the View Report button it looks like it is just posting back the parameters each and not running the report ... I suppose it has something to do with the way I remove the timestamp that is in the _endRequest handler, but I couldn't find any other way to remove the timestamp. When I look in the hrome dev tools I can see console.log messages and it removes the timestamps and logs my messages when I first select a date, but when I click the view report button it hits my console messages twice. log. Maybe there is a way not to hit the _endRequest handler when I click the View Report button, maybethis will fix my problem. Also open to other ideas. Below is the ReportViewer and jQuery html page to handle the datepicker.
<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>
source to share
No one has answered this question yet
Check out similar questions: