在ASP.NET子控件创建ASP.NET的ReportViewer;文档结构图按钮中断 [英] Create ASP.NET ReportViewer in a child control in ASP.NET; Document Map button breaks
问题描述
我们正与Visual Studio 2008中的ReportViewer控制一个奇怪的问题。具体而言,当我们有一个页面上的子控件,子控件本身承载了报表查看器,报告有一个文档结构图上显示/隐藏文档结构图按钮回发似乎丢失,所以文档结构图从未消失。我打了IPostBackEventHandler和似乎没有取得任何进展;所以我不认为我在照顾自己的ReportViewer实现该接口。总之,这里的code:
We are having a strange issue with the Visual Studio 2008 ReportViewer control. Specifically, when we have a child control on a page, and the child control itself hosts a report viewer, and the report has a document map, the postback on the show/hide document map button seems to be lost, so the document map never disappears. I played with IPostBackEventHandler and didn't seem to get anywhere; the ReportViewer itself implements that interface so I didn't think I cared. Anyway, here's the code:
Default.aspx的:
Default.aspx:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="ReportViewerDocumentMapButtonStrippedExample._Default" %>
<!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" >
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div runat="server" id="div">
</div>
</form>
</body>
</html>
Default.aspx.cs:
Default.aspx.cs:
using System;
namespace ReportViewerDocumentMapButtonStrippedExample {
public partial class _Default : System.Web.UI.Page {
protected void Page_Load(object sender, EventArgs e) {
}
protected override void CreateChildControls() {
base.CreateChildControls();
FindControl("div").Controls.Add(new rvControl());
}
}
}
rvControl.cs:
rvControl.cs:
using System.Collections.Generic;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using Microsoft.Reporting.WebForms;
namespace ReportViewerDocumentMapButtonStrippedExample {
public class rvControl : HtmlGenericControl {
protected override void CreateChildControls() {
base.CreateChildControls();
var rvMain = new ReportViewer {
EnableViewState = true,
ProcessingMode = ProcessingMode.Remote,
ShowRefreshButton = false,
AsyncRendering = true,
Width = new Unit(100, UnitType.Percentage),
Height = new Unit(2000, UnitType.Pixel),
ShowCredentialPrompts = false,
ID = "viewer",
};
rvMain.ServerReport.ReportPath = "/some/report/name";
Controls.Add(rvMain);
}
}
}
任何人有这样的想法?
Anyone have an idea on this?
推荐答案
微软为我们找到了答案。基本上,它是在ReportViewer控件和控件生存一些混乱。解决方法是一个简单的除了自定义控件:
Microsoft found the answer for us. Basically, it was some confusion in ReportViewer control and the control lifecycle. The fix is a simple addition to the custom control:
public override System.Web.UI.ControlCollection Controls {
get {
this.EnsureChildControls();
return base.Controls;
}
}
这篇关于在ASP.NET子控件创建ASP.NET的ReportViewer;文档结构图按钮中断的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!