在ASP.NET中的子控件中创建ASP.NET ReportViewer;文档结构图按钮中断

发布于 2024-08-09 13:26:31 字数 2235 浏览 6 评论 0原文

我们在使用 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>

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:

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

    }
}

有人对此有什么想法吗?

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:

<%@ 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:

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:

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

缱倦旧时光 2024-08-16 13:26:31

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

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

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;
    }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文