i have a main report and tow sub reports as show On-Demand, my problem is when click on sub report link everything is fine and first page as sub report will be shown ,but if i want to go to next page or export sub report as pdf just main report will be export. and if i want to go to next page crystal report viewer closed my sub report tab and back to second main report page my CrystalReportViewerPage.cs class
public partial class CrystalReportViewerPage : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (IsPostBack)
{
CrystalReportViewer1.ReportSource = (ReportDocument)Session["Report"];
}
else
{
if (string.IsNullOrEmpty(Page.RouteData.Values["userId"].ToString()))
throw new ArgumentNullException();
var userId = Guid.Parse(Page.RouteData.Values["userId"].ToString());
CrystalReportViewer1.ReportSource = CrystalController.Statements[userId];
Session["Report"] = CrystalController.Statements[userId];
}
}
}
and aspx page
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="CrystalReportViewerPage.aspx.cs" Inherits="Mahya.ITS.CityMan.Views.Shared.CrystalReportViewerPage" %>
<%@ Register TagPrefix="CR" Namespace="CrystalDecisions.Web" Assembly="CrystalDecisions.Web, Version=13.0.4000.0, Culture=neutral, PublicKeyToken=692fbea5521e1304" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<script src='<%=ResolveUrl("~/Content/crystalreportviewers/js/crviewer/crv.js")%>' type="text/javascript"></script>
<body style="margin: auto;">
<form id="form1" runat="server">
<div style="text-align: center; margin: auto; direction: rtl; display: table" >
<CR:CrystalReportViewer ID="CrystalReportViewer1" runat="server" AutoDataBind="true" BestFitPage="True"
ToolPanelView="None" EnableTheming="True" HasToggleGroupTreeButton="False" HasCrystalLogo="False" />
</div>
</form>
</body>
</html>
<iframe name="sif1" sandbox="allow-forms allow-modals allow-scripts" frameborder="0"></iframe>
CrystalDecisions.Web dll Version=13.0.4000.0
CodePudding user response:
So after many hours, finally found problem. Must initial source of report viewer in OnInit instead of page_load event. So every things is fine and report source will not be refill again.
protected void CrystalReportViewer1_OnInit(object sender, EventArgs e){
if (string.IsNullOrEmpty(Page.RouteData.Values["userId"].ToString()))
throw new ArgumentNullException();
var userId = Guid.Parse(Page.RouteData.Values["userId"].ToString());
CrystalReportViewer1.ReportSource = CrystalController.Statements[userId];
}