首页 > 解决方案 > 在 Kentico 中显示 SSRS 报告会导致 ClientID 错误,如何解释记录在案的解决方案?

问题描述

所以我在 SSRS 中部署了一个报告,我可以在 localhost 的托管位置查看它。现在我试图让报告显示在 Kentico webpart 的 ReportViewer 控件中。我收到错误:“内部错误:OnInit 之前的 ClientID 引用”。做了一些搜索,我找到了这篇文章:

https://devnet.kentico.com/articles/how-to-display-a-microsoft-sql-server-reporting-services-(ssrs)-report-in-kentico

它建议添加 ReportViewer “不是作为控件 (ascx),而是在 WebPart 的 On_Load 事件中添加以下内容:Controls.Add(ReportViewer)。

例子:

ReportViewer rv = new ReportViewer();
Controls.Add(rv);"

我不知道如何做到这一点。我尝试从 ascx 页面中删除控件并将以下内容添加到我的代码后面:

ReportViewer ReportViewer1 = new ReportViewer();
Controls.Add(ReportViewer1);

这没有做任何事情。这是我的代码隐藏:

using CMS.PortalControls;
using CMS.GlobalHelper;

using Telerik.Web.UI;
using System.Windows.Forms;
using Microsoft.Reporting.WebForms;

/**
 * [Comment Header Content]
 **/
public partial class CMSWebParts_Custom_Development_DispatchForm_Demo: 
CMSAbstractWebPart
{
// Global variables
public string paramId;
public string urlString;
// On page load events
protected void Page_Load(object sender, EventArgs e)
{
    // Check for postback status
    if (!IsPostBack)
        {
            // Set viewstate
        ViewState["RefUrl"] = Request.UrlReferrer.ToString();
        }
    // Set urlstring and parse for "Theid"

    urlString = Request.UrlReferrer.ToString();
    paramId = HttpUtility.ParseQueryString(urlString).Get("Theid");

    ReportViewer ReportViewer1 = new ReportViewer();
    ReportViewer1.ServerReport.ReportPath = "http://localhost/reportserver?%2fReport+Project1%2fReport1&rs:Command=Render";

    Controls.Add(ReportViewer1);
}

这是我的 ASCX:

<%@ Control Language="C#" AutoEventWireup="true" 
CodeFile="~/CMSWebParts/Custom/Development/DispatchForm_Demo.ascx.cs" 
Inherits="CMSWebParts_Custom_Development_DispatchForm_Demo" %>
<%@ Register assembly="CrystalDecisions.Web, Version=13.0.3500.0, 
Culture=neutral, PublicKeyToken=692fbea5521e1304" 
namespace="CrystalDecisions.Web" tagprefix="CR" %>
<%@ Register assembly="Microsoft.ReportViewer.WebForms" 
namespace="Microsoft.Reporting.WebForms" tagprefix="rsweb" %>
<style type="text/css">
.auto-style8 {
    width: 100%;
}
</style>

<rsweb:ReportViewer ID="ReportViewer1" runat="server" BackColor="" 
ClientIDMode="AutoID" HighlightBackgroundColor="" 
InternalBorderColor="204, 204, 204" InternalBorderStyle="Solid" 
InternalBorderWidth="1px" LinkActiveColor="" LinkActiveHoverColor="" 
LinkDisabledColor="" PrimaryButtonBackgroundColor="" 
PrimaryButtonForegroundColor="" PrimaryButtonHoverBackgroundColor="" 
PrimaryButtonHoverForegroundColor="" ProcessingMode="Remote" 
SecondaryButtonBackgroundColor="" SecondaryButtonForegroundColor="" 
SecondaryButtonHoverBackgroundColor="" 
SecondaryButtonHoverForegroundColor="" 
SplitterBackColor="" ToolbarDividerColor="" ToolbarForegroundColor="" 
ToolbarForegroundDisabledColor="" ToolbarHoverBackgroundColor="" 
ToolbarHoverForegroundColor="" ToolBarItemBorderColor="" 
ToolBarItemBorderStyle="Solid" ToolBarItemBorderWidth="1px" 
ToolBarItemHoverBackColor="" ToolBarItemPressedBorderColor="51, 102, 153" 
ToolBarItemPressedBorderStyle="Solid" ToolBarItemPressedBorderWidth="1px" 
ToolBarItemPressedHoverBackColor="153, 187, 226">
<ServerReport ReportPath="/Report Project1/Report1" />
</rsweb:ReportViewer>

编辑:好的,根据我收到的第一个建议,我添加了一个占位符,然后尝试使用以下代码添加控件:

    ReportViewer rv = new ReportViewer();
    Uri siteUri = new Uri("http://localhost/reportserver");
    rv.ServerReport.ReportServerUrl = siteUri;
    rv.ServerReport.ReportPath = "/Report Project1/Report1";
    plcContent.Controls.Add(rv); 

现在我没有收到错误,但 Web 表单中没有加载任何内容。越来越近?

标签: c#sql-serverreporting-servicesssrs-2008-r2kentico

解决方案


尝试在 ascx 中添加一个占位符:

<asp:PlaceHolder ID="plcContent" runat="server" />

然后在你的代码后面添加控件:

ReportViewer rv = new ReportViewer();
plcContent.Controls.Add(rv);

推荐阅读