【问题标题】:Displaying SSRS Reports in Kentico Results in ClientID Errors, How to Interpret Documented Solution?在 Kentico 中显示 SSRS 报告会导致 ClientID 错误,如何解释记录在案的解决方案?
【发布时间】:2018-11-26 20:47:56
【问题描述】:

所以我在 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-server reporting-services ssrs-2008-r2 kentico


    【解决方案1】:

    尝试在 ascx 中添加占位符:

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

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

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

    【讨论】:

    • 好吧,我 认为 更接近,但我不知道,因为使用我在底部原始问题中更新的代码,占位符中没有加载任何内容。但至少没有更多的错误。只是还没有看到任何东西。
    • 所以,仍在努力。在将控件添加到占位符之前,我还添加了 rv.Databind() 以查看是否有所作为。这导致了一个错误,指出报表查看器 Web 控件需要 Web 表单上的 ScriptManager。接下来,我将工具箱中的 ScriptManager 添加到页面。然后我收到一条消息说“只能将 ScriptManager 的一个实例添加到页面中”。显然我的母版页也有一个 ScriptManager,但我什至不确定我是否在正确地吠叫。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-10-26
    • 1970-01-01
    相关资源
    最近更新 更多