代码之家  ›  专栏  ›  技术社区  ›  MikeBaz - MSFT

在ASP.NET中的子控件中创建ASP.NET ReportViewer;文档映射按钮中断

  •  2
  • MikeBaz - MSFT  · 技术社区  · 16 年前

    Visual Studio 2008 ReportViewer控件出现了一个奇怪的问题。具体来说,当我们在页面上有一个子控件,而子控件本身承载一个报表查看器,并且报表具有文档映射时,显示/隐藏文档映射按钮上的回发似乎丢失了,因此文档映射永远不会消失。我使用了ipostbackEventHandler,似乎什么也没有得到;ReportViewer本身实现了这个接口,所以我认为我不在乎。不管怎样,代码如下:

    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>
    

    默认.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());
            }
        }
    }
    

    RVCONDS.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);
            }
    
        }
    }
    

    有人知道这个吗?

    1 回复  |  直到 15 年前
        1
  •  2
  •   MikeBaz - MSFT    15 年前

    微软为我们找到了答案。基本上,它在ReportViewer控件和控件生命周期中存在一些混淆。修复是对自定义控件的简单添加:

    public override System.Web.UI.ControlCollection Controls {
        get {
            this.EnsureChildControls();
            return base.Controls;
        }
    }