Link to home
Start Free TrialLog in
Avatar of ilyagzak
ilyagzak

asked on

Event handler subroutine for VB.NET SSRS subreport never gets invoked

I work in VS 2015 VB.Net
I creatd SSRS report with subrepot.
I read that to do that you have to populate both your main report and subreport in code, and for the subreport you create an event handler to populate.
In my case the subroutine that handles the event handler never gets invoked, and the subreport is not getting populated. Report displays only the main report, the subreport returns a message: Error: Subreport could not be shown.
Here are the references I have on the page:
Imports System.Data.SqlClient
Imports Microsoft.Reporting.WebForms
Here is my page load event:
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        If Not IsPostBack Then
            ReportViewer1.ProcessingMode = ProcessingMode.Local
            ReportViewer1.LocalReport.DataSources.Clear()
            ReportViewer1.LocalReport.ReportPath = Server.MapPath(".") + "/SSRSReports/" + "PvPDOrder.rdlc"
            ReportViewer1.LocalReport.DataSources.Add(GetReportDataSource)
            AddHandler Me.ReportViewer1.LocalReport.SubreportProcessing, AddressOf SubreportProcessingEventHandler
            Me.ReportViewer1.LocalReport.Refresh()
        End If
    End Sub

   Public Sub SubreportProcessingEventHandler(ByVal sender As Object, ByVal e As SubreportProcessingEventArgs)
        Try
            e.e.DataSources.Add(GetSubreportDataSource)
        Catch ex As Exception
            ' MessageBox.Show(ex.Message, My.Application.Info.Title, MessageBoxButtons.OK, MessageBoxIcon.Error)
        End Try
  End Sub

  My problem is that the code never reaches this procedure SubreportProcessingEventHandler
  I use a debugger,  it never goes in there.
  Could you please help.
Avatar of AndyAinscow
AndyAinscow
Flag of Switzerland image

Is this line of code
If Not IsPostBack Then
preventing the event handler being added?
Just use th debugger to check the Page_Load event is called and what the value of IsPostBack is.
Avatar of ilyagzak
ilyagzak

ASKER

Hi Andy,
The event handler is added, it is just never invoked, that is the issue.
Here I added two pictures to demonstrate.
On the first picture that is PageLoad event, the dubugger goes to the AddHandler line.
I believe that on the line Me.ReportViewer1.LocalReport.Refresh() this event should be invokes, but it does not happen.
My second picture shows the procedure SubreportProcessingEventHandler that handles the event.
The debugger never gets there.
Please see the attached MS Word file with the two pictures.SubreportIssue.docxSubreportIssue.docx
OK.  Is the subreport an rdlc file?  I've found something where the event didn't fire for an .rdl subreport but a simple rename to the rdlc extension cured it.
Replace the report that you are using as the subreport, with another report, which should be super-simple, have no datasources at all, just one static textbox. Comment out AddHandler in the code. Will the subreport show up?

In the code you specify the path for the main report. What about the path for the subreport - what is the property ReportName of the subreport? is the file reportname.rdlc in place?
My file has the extension .rdlc
I tried to put a simple subreport without a data source, it came up fine with just one text box.
Vadim, what the next step you suggest?
My subreport is in place.
If I try to rename the subreport the system gets me the error message the report is not found
Does the event fire when the report is the simple one?

also, just noticed... "e.e.DataSources" - this "e.e" - is that the way it's supposed to be?
The subreport 'PvPDCastDiscrepancy' could not be found at the specified location
that is what I get when the subreport is not there
Allright, so now we know that the subreport source is found. But still it fails to load. At the same time, the simple subreport does load. Which probably tells us that the problem is in the "real" subreport. It fails to load, which is why the event does not fire.

Now you need to find out why the "complex" subreport does not load. I would make a copy of it and started to remove one piece after another, until it loaded. This is how you will find the critical piece responsible for the failure to load.
OK, thank you. The failure though was prior to the report being loaded. The event to handle the load did not fire up, it was nothing to handle. I will play around a bit and let you know.
No progress unfortunately.
Still cannot make the execution to go to the subreport handler stored procedure.
It went there couple of times, then stoped going there again.
I tried to add the second subreport and removed the first one.
The execution did not go the second sub report event handler procedure.
I removed the second subreport and put back the first one.
The execution does not go into the event handler procedure that used to work.
When I put back the simple subreport with one data field it works.
ASKER CERTIFIED SOLUTION
Avatar of Vadim Rapp
Vadim Rapp
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thank you very much for your help.
I will start another question on the topic of SSRS.
Please help!
Vadim gave me practical steps to take to fix the issue.