Answered by:
How to make Multi Page Reports

Question
-
User1948463016 posted
Hi,
I've been able to resolve how to get the Navigation Toolbar to display in debug mode. But it still doesn't work.
When I try to navigate to the second page in the report it kicks off the Page_Init event. Here's my code:
Private Sub CReportForm_Init(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Init
'Identify calling page... For future use to identify the required report
' when there are multiple selections possible... so the CReportForm and the
' Report Viewer will become re-usable.
If Page.PreviousPage.ToString IsNot Nothing Then
Dim txt As String = Page.PreviousPage.ToString
'Dim txt2 As String = Page.PreviousPage.c
Dim rptDoc As New CrystalDecisions.CrystalReports.Engine.ReportDocument
Dim s As String = Server.MapPath(".")
Dim field1 As String = CType(Session.Item("field1"), String)
Select Case txt
Case Is = "ASP.selectBLABLABLA_aspx"
s = s & "\BLABLABLA.rpt"
rptDoc.Load(s)
CrystalReportViewer1.ReportSource = rptDoc
Case Else
If field1 = "btnTestRpt" Then
s = s & "\CrystalReport1.rpt"
rptDoc.Load(s)
CrystalReportViewer1.DisplayToolbar = True
CrystalReportViewer1.ReportSource = rptDoc
End If
End Select
End If
End SubOn the first iteration of init sub ... The first page of the report ("\CrystalReport1.rpt") displays successfully.
When I try to navigate to the second page, the [ Page.PreviousPage ] is null, so I get an exception. I tried avoiding the entire Init process with
' If Page.IsPostBack = False Then '
This gets me past the 'Null' exception, but when I try to navigate to Page 2, instead I get the other report displayed("\BLABLABLA.rpt")... even though the code block to load that report is never executed.
Obviously there's a lot I don't know about this. Any help is appreciated.
Tom
Friday, August 28, 2015 10:40 AM
Answers
-
User1223857158 posted
Hi wherewasi,
When I try to navigate to the second page, the [ Page.PreviousPage ] is null, so I get an exception. I tried avoiding the entire Init process with
' If Page.IsPostBack = False Then '
This gets me past the 'Null' exception, but when I try to navigate to Page 2, instead I get the other report displayed("\BLABLABLA.rpt")... even though the code block to load that report is never executed.
From your description, I suppose you could define a session and save the page index into session. Then, when page is post back, you could get the page index from the session.
You could refer to the following code:
If Page.IsPostBack = False Then If Page.PreviousPage.ToString IsNot Nothing Then Dim txt As String = Page.PreviousPage.ToString //define a session to save the txt 'Dim txt2 As String = Page.PreviousPage.c Dim rptDoc As New CrystalDecisions.CrystalReports.Engine.ReportDocument Dim s As String = Server.MapPath(".") Dim field1 As String = CType(Session.Item("field1"), String) Select Case txt Case Is = "ASP.selectBLABLABLA_aspx" s = s & "\BLABLABLA.rpt" rptDoc.Load(s) CrystalReportViewer1.ReportSource = rptDoc Case Else If field1 = "btnTestRpt" Then s = s & "\CrystalReport1.rpt" rptDoc.Load(s) CrystalReportViewer1.DisplayToolbar = True CrystalReportViewer1.ReportSource = rptDoc End If End Select End If Else //Get the txt from session Dim rptDoc As New CrystalDecisions.CrystalReports.Engine.ReportDocument Dim s As String = Server.MapPath(".") Dim field1 As String = CType(Session.Item("field1"), String) Select Case txt Case Is = "ASP.selectBLABLABLA_aspx" s = s & "\BLABLABLA.rpt" rptDoc.Load(s) CrystalReportViewer1.ReportSource = rptDoc Case Else If field1 = "btnTestRpt" Then s = s & "\CrystalReport1.rpt" rptDoc.Load(s) CrystalReportViewer1.DisplayToolbar = True CrystalReportViewer1.ReportSource = rptDoc End If End Select End If
You could also change the session value in button click event.
Best regards,
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Friday, September 18, 2015 4:55 AM
All replies
-
User1948463016 posted
Anyone?
Friday, September 11, 2015 8:52 AM -
User1243880387 posted
Can you please explain whether the second page has the same report section displayed or does it shows another reports as a subreport being placed in detail section of the main report.
Basically I am trying to understand, whether the same report will be shown on the other pages and that is giving the error, or there is another report added as a subreport, which has issues.
Monday, September 14, 2015 4:21 AM -
User1948463016 posted
Thanks for the reply.
The second page shows that it is still the 'Main Report' ... and it is. But It's a completely different report.
Tuesday, September 15, 2015 12:22 PM -
User1223857158 posted
Hi wherewasi,
When I try to navigate to the second page, the [ Page.PreviousPage ] is null, so I get an exception. I tried avoiding the entire Init process with
' If Page.IsPostBack = False Then '
This gets me past the 'Null' exception, but when I try to navigate to Page 2, instead I get the other report displayed("\BLABLABLA.rpt")... even though the code block to load that report is never executed.
From your description, I suppose you could define a session and save the page index into session. Then, when page is post back, you could get the page index from the session.
You could refer to the following code:
If Page.IsPostBack = False Then If Page.PreviousPage.ToString IsNot Nothing Then Dim txt As String = Page.PreviousPage.ToString //define a session to save the txt 'Dim txt2 As String = Page.PreviousPage.c Dim rptDoc As New CrystalDecisions.CrystalReports.Engine.ReportDocument Dim s As String = Server.MapPath(".") Dim field1 As String = CType(Session.Item("field1"), String) Select Case txt Case Is = "ASP.selectBLABLABLA_aspx" s = s & "\BLABLABLA.rpt" rptDoc.Load(s) CrystalReportViewer1.ReportSource = rptDoc Case Else If field1 = "btnTestRpt" Then s = s & "\CrystalReport1.rpt" rptDoc.Load(s) CrystalReportViewer1.DisplayToolbar = True CrystalReportViewer1.ReportSource = rptDoc End If End Select End If Else //Get the txt from session Dim rptDoc As New CrystalDecisions.CrystalReports.Engine.ReportDocument Dim s As String = Server.MapPath(".") Dim field1 As String = CType(Session.Item("field1"), String) Select Case txt Case Is = "ASP.selectBLABLABLA_aspx" s = s & "\BLABLABLA.rpt" rptDoc.Load(s) CrystalReportViewer1.ReportSource = rptDoc Case Else If field1 = "btnTestRpt" Then s = s & "\CrystalReport1.rpt" rptDoc.Load(s) CrystalReportViewer1.DisplayToolbar = True CrystalReportViewer1.ReportSource = rptDoc End If End Select End If
You could also change the session value in button click event.
Best regards,
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Friday, September 18, 2015 4:55 AM -
User1948463016 posted
Lorris,
Sorry for not responding sooner. Your answer/solutiuon here is pure gold. I can't thank you enough.
Regards,
Tom
Friday, October 2, 2015 11:41 AM