Page 1 of 1

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

Posted: Thu Jan 17, 2013 3:07 am
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

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

Posted: Thu Jan 17, 2013 2:00 pm
by Vladimir
Hello,

Please try to use this code:

Code: Select all

reportViewer.ResetReport();
reportViewer.Report = report;
Thank you.

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

Posted: Thu Jan 17, 2013 10:39 pm
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.

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

Posted: Fri Jan 18, 2013 7:59 am
by HighAley
Hello.

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

Thank you.