We have various document libraries in a sharepoint portal that contains our report rpt files and we use an external web app to view reports in the libraries.
The app consists of one Default.aspx page containing the CrystalReportViewer control and a label control.
The parameters are set in the rpt file and if any and the report viewer will prompt the user for them.
The problem is that whenever we try to navigate, export, print, basically use any function of the toolbar, the page of course refreshes and goes back to the parameter input form.
To fix it I had to do a few things.
- Saved the report document into a session variable and load it back in after postback but;
- Disabled the parameter prompt on postbacks.
- To fix the paging issue, I had to move the code from the Page_Load to the Page_Init (found the solution here: http://www.crystalreportsbook.com/forum/forum_posts.asp?TID=2709)
protected void Page_Init(object sender, EventArgs e)
{
// Exit if the session variable containing the report document is null (or does not exist).
if (null == Session["ReportDocument"]) return;
// Set the Crystal Report Viewer source to our previously saved report document.
var crdoc = (ReportDocument)Session["ReportDocument"];
crViewer.ReportSource = crdoc;
}
protected void Page_Load(object sender, EventArgs e)
{
// We only want to see the parameter form on the initial page load.
crViewer.EnableParameterPrompt = !IsPostBack;
// We only want to continue on postback and if the session variable containing
// the report document is not null (exists).
if (IsPostBack && null != Session["ReportDocument"]) return;
// Load the rpt file from the sharepoint library and display it in the viewer.
// The report document is saved into the session variable in this method.
DisplayReport();
}