Reputation: 3110
I have created a Crystal Report. It is working fine. Then I tried to use it in Asp.Net using
<CR:CrystalReportViewer ID="CrystalReportViewer1" runat="server"
DisplayGroupTree="False" />
The first time, it works fine but when I click on the print
button, the report disappears and gives an error. When I move my BindReport
method out of if(!IsPostBack)
then it starts working fine.
Below gives error when print button is clicked:
protected void Page_Load(object sender, EventArgs e)
{
if(!IsPostBack)
{
BindReport();
}
}
But this works fine
protected void Page_Load(object sender, EventArgs e)
{
BindReport();
}
Can someone help me understand what is the reason?
Upvotes: 0
Views: 777
Reputation: 28990
Insofar as only the mouse click events of the CrystalReportViewer control can be serialized into ViewState, binding to a report class that can be serialized generates an insoluble problem when reloading pages:
1 If the report binding code is placed in a Not IsPostBack conditional block the mouse click events from ViewState are retained, but the binding of the report does not take place, and an exception is thrown.
2 If the report binding code is placed outside the conditional block, the report is bound correctly, but the contents of ViewState is crushed in the process, and mouse click events are lost.
Nota : This situation occurs most often when clicks are made in a report to several pages at the CrystalReportViewer control. The report continues then mysteriously back on page 1.
Solution
Put the binding code CrystalReportViewer control in the Init event
Link : http://msdn.microsoft.com/fr-fr/library/ms225455%28v=vs.90%29.aspx
Upvotes: 2