0

So I have deployed a report in SSRS, and I can view it at its hosting location at localhost. Now I'm trying to get the report to display in a ReportViewer control in a Kentico webpart. I get the error: "Internal error: ClientID reference before OnInit". Doing some searching I found this article:

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

which advises to add the ReportViewer "not as an control (ascx), but in the On_Load event of the WebPart by adding the following: Controls.Add(ReportViewer).

Example:

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

I have no clue how to make this happen. I have tried deleting the control from the ascx page and adding the following to my code behind:

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

This didn't do anything. Here is my codebehind:

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

And here is my 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>

EDIT: Okay so as per the first suggestion I received, I added a placeholder and then attempted to add the control with this code:

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

Now I don't get an error but nothing loads in the web form. Getting closer?

Marley Stacy
  • 100
  • 12

1 Answers1

0

Try adding a placeholder in your ascx:

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

Then in your code behind add the control to that:

ReportViewer rv = new ReportViewer();
plcContent.Controls.Add(rv);
Zach Perry
  • 746
  • 3
  • 12
  • Well I *think* that's closer, but I don't know because nothing loads in the placeholder using the code I updated in the original question at the bottom. But no more errors at least. Just don't see anything yet. – Marley Stacy Nov 27 '18 at 13:13
  • So, still working on this. I added also rv.Databind() before adding the control to the placeholder to see if that made a difference. This resulted in an error saying the Report Viewer Web Control Requires a ScriptManager on the web form. Next I added a ScriptManager from the toolbox to the page. I then got a message saying "Only one instance of a ScriptManager can be added to the page". Apparently my master page has a ScriptManager as well but I'm not even sure if I'm barking up the right tree or not. – Marley Stacy Nov 27 '18 at 16:07