Asp.net SSRS ReportViewer 2010 Iframe IE问题
我的问题与试图在MVC应用程序中包含SSRS(SQL Server)报告有关Asp.net SSRS ReportViewer 2010 Iframe IE问题,asp.net,asp.net-mvc,asp.net-ajax,reporting-services,reportviewer,Asp.net,Asp.net Mvc,Asp.net Ajax,Reporting Services,Reportviewer,我的问题与试图在MVC应用程序中包含SSRS(SQL Server)报告有关 <script type="text/javascript"> $(window).load(function () { $.post('/Report.aspx', { val1: "Hello World" }, function (data) { var rv_frame = document.getElementById('Frame1');
<script type="text/javascript">
$(window).load(function () {
$.post('/Report.aspx', { val1: "Hello World" }, function (data) {
var rv_frame = document.getElementById('Frame1');
rv_frame = (rv_frame.contentWindow) ? rv_frame.contentWindow : (rv_frame.contentDocument.document) ? rv_frame.contentDocument.document : rv_frame.contentDocument;
rv_frame.document.open();
rv_frame.document.write(data);
rv_frame.document.close();
});
});
</script>
我已经决定采用混合解决方案,即在中使用带有ReportViewer控件的WebForm,然后在MVC视图页面上使用此WebForm页面的iframe引用。棘手的部分是iframe需要使用报表动态填充,而不是使用src,因为要将参数发布到WebForm
<script type="text/javascript">
$(window).load(function () {
$.post('/Report.aspx', { val1: "Hello World" }, function (data) {
var rv_frame = document.getElementById('Frame1');
rv_frame = (rv_frame.contentWindow) ? rv_frame.contentWindow : (rv_frame.contentDocument.document) ? rv_frame.contentDocument.document : rv_frame.contentDocument;
rv_frame.document.open();
rv_frame.document.write(data);
rv_frame.document.close();
});
});
</script>
它在Firefox和Chrome中运行良好,但是IE抛出了一个“Sys is Undefined”javascript错误
<script type="text/javascript">
$(window).load(function () {
$.post('/Report.aspx', { val1: "Hello World" }, function (data) {
var rv_frame = document.getElementById('Frame1');
rv_frame = (rv_frame.contentWindow) ? rv_frame.contentWindow : (rv_frame.contentDocument.document) ? rv_frame.contentDocument.document : rv_frame.contentDocument;
rv_frame.document.open();
rv_frame.document.write(data);
rv_frame.document.close();
});
});
</script>
在iframe上使用src在IE中工作,但我找不到发布参数的方法(由于可能的长度,我不想使用/Report.aspx?param1=test之类的东西)
<script type="text/javascript">
$(window).load(function () {
$.post('/Report.aspx', { val1: "Hello World" }, function (data) {
var rv_frame = document.getElementById('Frame1');
rv_frame = (rv_frame.contentWindow) ? rv_frame.contentWindow : (rv_frame.contentDocument.document) ? rv_frame.contentDocument.document : rv_frame.contentDocument;
rv_frame.document.open();
rv_frame.document.write(data);
rv_frame.document.close();
});
});
</script>
这是一个ASP.NETMVC2项目,.NET4,Windows7x74上的VisualStudio2010,如果有帮助的话
<script type="text/javascript">
$(window).load(function () {
$.post('/Report.aspx', { val1: "Hello World" }, function (data) {
var rv_frame = document.getElementById('Frame1');
rv_frame = (rv_frame.contentWindow) ? rv_frame.contentWindow : (rv_frame.contentDocument.document) ? rv_frame.contentDocument.document : rv_frame.contentDocument;
rv_frame.document.open();
rv_frame.document.write(data);
rv_frame.document.close();
});
});
</script>
下面是代码(如果有人需要,我可以提供VS2010项目文件)
<script type="text/javascript">
$(window).load(function () {
$.post('/Report.aspx', { val1: "Hello World" }, function (data) {
var rv_frame = document.getElementById('Frame1');
rv_frame = (rv_frame.contentWindow) ? rv_frame.contentWindow : (rv_frame.contentDocument.document) ? rv_frame.contentDocument.document : rv_frame.contentDocument;
rv_frame.document.open();
rv_frame.document.write(data);
rv_frame.document.close();
});
});
</script>
在我的网络表单中:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Report.aspx.cs" Inherits="SSRSMVC.Views.Home.Report" %>
<%@ Register Assembly="Microsoft.ReportViewer.WebForms, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"
Namespace="Microsoft.Reporting.WebForms" TagPrefix="rsweb" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<body>
<form id="RSForm" runat="server">
<asp:ScriptManager ID="ScriptManager" runat="server" EnablePartialRendering="true" ScriptMode="Release">
</asp:ScriptManager>
<asp:UpdatePanel ID="ReportViewerUP" runat="server">
<ContentTemplate>
<rsweb:ReportViewer ID="ReportViewer" runat="server" Width="100%" Height="380px" ProcessingMode="Local"
InteractivityPostBackMode="AlwaysAsynchronous" AsyncRendering="true">
<LocalReport ReportPath="Models\\TestReport.rdlc">
</LocalReport>
</rsweb:ReportViewer>
</ContentTemplate>
</asp:UpdatePanel>
</form>
</body>
</html>
<script type="text/javascript">
$(window).load(function () {
$.post('/Report.aspx', { val1: "Hello World" }, function (data) {
var rv_frame = document.getElementById('Frame1');
rv_frame = (rv_frame.contentWindow) ? rv_frame.contentWindow : (rv_frame.contentDocument.document) ? rv_frame.contentDocument.document : rv_frame.contentDocument;
rv_frame.document.open();
rv_frame.document.write(data);
rv_frame.document.close();
});
});
</script>
最后是我的查看页面,
<script type="text/javascript">
$(window).load(function () {
$.post('/Report.aspx', { val1: "Hello World" }, function (data) {
var rv_frame = document.getElementById('Frame1');
rv_frame = (rv_frame.contentWindow) ? rv_frame.contentWindow : (rv_frame.contentDocument.document) ? rv_frame.contentDocument.document : rv_frame.contentDocument;
rv_frame.document.open();
rv_frame.document.write(data);
rv_frame.document.close();
});
});
</script>
$(窗口)。加载(函数(){
$.post('/Report.aspx',{val1:“Hello World”},函数(数据){
var rv_frame=document.getElementById('Frame1');
rv_frame=(rv_frame.contentWindow)?rv_frame.contentWindow:(rv_frame.contentDocument.document)?rv_frame.contentDocument.document:rv_frame.contentDocument;
rv_frame.document.open();
rv_框架文件写入(数据);
rv_frame.document.close();
});
});
解决方案似乎是使用表单元素发布然后填充iframe,我还发布了一个Microsoft Connect错误,因为iframe中的任何Microsoft AJAX都会导致JavaScript错误“sys is undefined”,我尝试了1个脚本管理器和1个更新面板,但得到了相同的错误
<script type="text/javascript">
$(window).load(function () {
$.post('/Report.aspx', { val1: "Hello World" }, function (data) {
var rv_frame = document.getElementById('Frame1');
rv_frame = (rv_frame.contentWindow) ? rv_frame.contentWindow : (rv_frame.contentDocument.document) ? rv_frame.contentDocument.document : rv_frame.contentDocument;
rv_frame.document.open();
rv_frame.document.write(data);
rv_frame.document.close();
});
});
</script>
解决方案代码
<script type="text/javascript">
$(window).load(function () {
$.post('/Report.aspx', { val1: "Hello World" }, function (data) {
var rv_frame = document.getElementById('Frame1');
rv_frame = (rv_frame.contentWindow) ? rv_frame.contentWindow : (rv_frame.contentDocument.document) ? rv_frame.contentDocument.document : rv_frame.contentDocument;
rv_frame.document.open();
rv_frame.document.write(data);
rv_frame.document.close();
});
});
</script>
<div id="HiddenFormTarget" style="display:none;"></div>
<iframe frameborder="0" id="Frame1" name="Frame1" style="width: 100%;height: 400px; overflow: hidden;">
</iframe>
<script type="text/javascript">
function ProcessReport() {
var form = $('<form method="post" target="Frame1" action="/Report.aspx"></form>');
form.append('<input type="hidden" id="val1" name="val1" value="Hello World!!!" />');
$("#HiddenFormTarget").append(form);
form.submit();
$("#HiddenFormTarget").empty();
}
$(window).load(function () {
ProcessReport();
});
$("H2").click(function () { ProcessReport(); });
</script>
函数ProcessReport(){
变量形式=$('');
格式。附加(“”);
$(“#HiddenFormTarget”)。追加(表格);
表单提交();
$(“#HiddenFormTarget”).empty();
}
$(窗口)。加载(函数(){
ProcessReport();
});
$(“H2”)。单击(函数(){ProcessReport();});
<script type="text/javascript">
$(window).load(function () {
$.post('/Report.aspx', { val1: "Hello World" }, function (data) {
var rv_frame = document.getElementById('Frame1');
rv_frame = (rv_frame.contentWindow) ? rv_frame.contentWindow : (rv_frame.contentDocument.document) ? rv_frame.contentDocument.document : rv_frame.contentDocument;
rv_frame.document.open();
rv_frame.document.write(data);
rv_frame.document.close();
});
});
</script>