How do I return the page to 1 when viewing a new report?

Stimulsoft Reports.WEB discussion
Post Reply
Scottioioio
Posts: 47
Joined: Thu Dec 20, 2012 6:58 pm

How do I return the page to 1 when viewing a new report?

Post by Scottioioio »

In my application I have a web page that lists the reports a user can view. If a user clicks on a report name it sends the user to ViewReport.aspx?ID=xxx, where xxx is the report ID that in my database contains information as to the report path (SalesInvoice.mrt, for example) and the data to load for that report. The ViewReport.aspx page uses the StiWebViewer web control to display the report using code like so:

Code: Select all

// Get the report file path
string reportFilePath = "..."; // depends on xxx

StiReport report = new StiReport();
report.Load(Server.MapPath(reportFilePath));

report.Dictionary.Variables.Add("ReportId", this.ReportId);

reportViewer.Report = report;
Here reportViewer is the StiWebViewer web control.

The issue I'm having is that if a user opens one report and moves to page 3, say, when they go back to the report list and then open a new report it starts them on page 3 (rather than page 1).

How do I get it so that whenever the user opens a new page they are sent back to the first page?

I've tried the following:

Code: Select all

reportViewer.ResetPageNumberOnAssignNewReport = true;
But had no luck. Also tried this:

Code: Select all

report.PageNumber = 1;
But no dice.

Thanks
Vladimir
Posts: 1462
Joined: Fri Apr 13, 2007 4:05 am
Location: Earth

Re: How do I return the page to 1 when viewing a new report?

Post by Vladimir »

Hello,

Please try to use this code:

Code: Select all

reportViewer.ResetReport();
reportViewer.Report = report;
Thank you.
Scottioioio
Posts: 47
Joined: Thu Dec 20, 2012 6:58 pm

Re: How do I return the page to 1 when viewing a new report?

Post by Scottioioio »

Vladimir, I tried that code but it did not work - the last page number that I viewed the prior report on is the same page number that the new report starts on.

However, after some tinkering, I found the following met my needs:

Code: Select all

if (!Page.IsPostBack)
    reportViewer.ResetCurrentPage();

reportViewer.Report = report;
It was imperative that the call to reportViewer.ResetCurrentPage() only happen on the first visit to the page (and not on postbacks) otherwise the report would be reset to the first page every time I tried to change the page.

But note that what worked is ResetCurrentPage, rather than ResetReport.
HighAley
Posts: 8430
Joined: Wed Jun 08, 2011 7:40 am
Location: Stimulsoft Office

Re: How do I return the page to 1 when viewing a new report?

Post by HighAley »

Hello.

We are glad to work with such costumers.
Let us know if you need any additional help.

Thank you.
Post Reply