I’m using a user control, and added my report viewer and a custom toolbar. I want to create a custom navigation for it aswell, but for some reason when I want to check the total pages to decide whether or not to show the navigation buttons it either returns 0 or “This expression causes side effects and will not be evaluated” error..
I’ve ran out of ideas and not quite sure where to go from here..
<rsweb:reportviewer
ID="rvReports"
runat="server" ShowToolBar="False"
SizeToReportContent="True" AsyncRendering="false" />
codebehind:
rds = new Microsoft.Reporting.WebForms.ReportDataSource("dsName", myclasstoload());
rvReports.LocalReport.DataSources.Add(rds);
rvReports.PageCountMode = PageCountMode.Actual;
rvReports.LocalReport.Refresh();
rvReports.DataBind();
if (rvReports.LocalReport.GetTotalPages() > 1)
{
liFirst.Visible = true;
liPrevious.Visible = true;
liNext.Visible = true;
liLast.Visible = true;
}
this is all on the databind event in my usercontrol (.ascx). Any help is more than appreciated.
This msdn question is probably your answer, the
GetTotalPages()method can’t be called until after the report has rendered. The relevant quote:See also the ASP.NET Page Lifecycle for reference.