Click here to Skip to main content
15,881,882 members
Please Sign up or sign in to vote.
3.40/5 (2 votes)
See more:
Dear All,

I am using crystal report in asp.net 3.5 Application.
The problem is that whenever any of the toolbar buttons is clicked first time it doesn't respond even the page is postbacked,and on second click onwards it works fine.I have put the code in Page_Init event to bind report.

looking forward for your kind help.
Thanks in advance!!!

Supriya Srivastava


Code is Here:

C#
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;  
using CrystalDecisions.Shared;
using CrystalDecisions.CrystalReports.Engine;
using CrystalDecisions.CrystalReports; 


public partial class Employee_Reports_Forms_frmPrnt_attendance_Summary : System.Web.UI.Page
{
    Common cmnsql = new Common();
    ReportDocument RptDoc;
    DataDefinition df;
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            Session["RptDoc"] = null;
            RptDoc = null;
            if (Request.QueryString["Title"] != null)
            {
                hid_RprtTitle.Value = Convert.ToString(Request.QueryString["Title"]);
            }
            hid_unm.Value = Convert.ToString(Session["UName"]);
            hid_RprtName.Value = Convert.ToString(Session["Report_Name"]);
            hid_CompCode.Value = Convert.ToString(Session["Comp_Code"]);
            hid_MonYr.Value = Convert.ToString(Session["MonYr"]);
            if (Session["Val"] != null)
            {
                hid_Val.Value = Convert.ToString(Session["Val"]);
            }
            else
            {
                hid_Val.Value = "";
            }
            LoadReport();
        }
    }
   
    private void LoadReport()
    {
        try
        {
            string Rprt_Name = "~\\FAS_Reports\\" + hid_RprtName.Value;
            DataTable dtattend = (DataTable)Session["dtattend"];
            RptDoc = new ReportDocument();
            RptDoc.Load(Server.MapPath(Rprt_Name));
            RptDoc.SetDataSource(dtattend);
            df = RptDoc.DataDefinition;
            RptDoc.Load(Server.MapPath(Rprt_Name));
            CrystalReportViewer1.ReportSource = RptDoc;
            CrystalReportViewer1.ID = "DownloadedReport";
            Session["RptDoc"]= RptDoc;
        }
        catch (Exception)
        {
            return;
        }
    }
    private void Page_Init(object sender, EventArgs e)
    {
        
            if (Session["RptDoc"] != null)
            {
                CrystalReportViewer1.ReportSource = (ReportDocument)Session["RptDoc"];
                CrystalReportViewer1.DataBind();
            }
    }
}
Posted
Updated 10-Aug-11 20:26pm
v4
Comments
thatraja 10-Aug-11 9:31am    
Show the code
Supriya Srivastav 11-Aug-11 2:16am    
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using CrystalDecisions.Shared;
using CrystalDecisions.CrystalReports.Engine;
using CrystalDecisions.CrystalReports;


public partial class Employee_Reports_Forms_frmPrnt_attendance_Summary : System.Web.UI.Page
{
Common cmnsql = new Common();
ReportDocument RptDoc;
DataDefinition df;
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
Session["RptDoc"] = null;
RptDoc = null;
if (Request.QueryString["Title"] != null)
{
hid_RprtTitle.Value = Convert.ToString(Request.QueryString["Title"]);
}
hid_unm.Value = Convert.ToString(Session["UName"]);
hid_RprtName.Value = Convert.ToString(Session["Report_Name"]);
hid_CompCode.Value = Convert.ToString(Session["Comp_Code"]);
hid_MonYr.Value = Convert.ToString(Session["MonYr"]);
if (Session["Val"] != null)
{
hid_Val.Value = Convert.ToString(Session["Val"]);
}
else
{
hid_Val.Value = "";
}
LoadReport();
}
}

private void LoadReport()
{
try
{
string Rprt_Name = "~\\FAS_Reports\\" + hid_RprtName.Value;
DataTable dtattend = (DataTable)Session["dtattend"];
RptDoc = new ReportDocument();
RptDoc.Load(Server.MapPath(Rprt_Name));
RptDoc.SetDataSource(dtattend);
df = RptDoc.DataDefinition;
RptDoc.Load(Server.MapPath(Rprt_Name));
CrystalReportViewer1.ReportSource = RptDoc;
CrystalReportViewer1.ID = "DownloadedReport";
Session["RptDoc"]= RptDoc;
}
catch (Exception)
{
return;
}
}
private void Page_Init(object sender, EventArgs e)
{

if (Session["RptDoc"] != null)
{
CrystalReportViewer1.ReportSource = (ReportDocument)Session["RptDoc"];
CrystalReportViewer1.DataBind();
}
}
}

1 solution

Move your Page_Load() code to Page_Init()

Try this link
Crystal Report viewer navigation buttons not working[^](Read sheikhusmanshakeel's reply which has code)
 
Share this answer
 
Comments
Supriya Srivastav 11-Aug-11 2:31am    
Ya I did that,but no effect in behave

now code is like:

using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using CrystalDecisions.Shared;
using CrystalDecisions.CrystalReports.Engine;
using CrystalDecisions.CrystalReports;


public partial class Employee_Reports_Forms_frmPrnt_attendance_Summary : System.Web.UI.Page
{
Common cmnsql = new Common();
ReportDocument RptDoc;
DataDefinition df;
protected void Page_Load(object sender, EventArgs e)
{

}

private void LoadReport()
{
try
{
string Rprt_Name = "~\\FAS_Reports\\" + hid_RprtName.Value;
DataTable dtattend = (DataTable)Session["dtattend"];
RptDoc = new ReportDocument();
RptDoc.Load(Server.MapPath(Rprt_Name));
RptDoc.SetDataSource(dtattend);
df = RptDoc.DataDefinition;
RptDoc.Load(Server.MapPath(Rprt_Name));
CrystalReportViewer1.ReportSource = RptDoc;
CrystalReportViewer1.ID = "DownloadedReport";
Session["RptDoc"]= RptDoc;
}
catch (Exception)
{
return;
}
}
private void Page_Init(object sender, EventArgs e)
{
if (!IsPostBack)
{
Session["RptDoc"] = null;
RptDoc = null;
if (Request.QueryString["Title"] != null)
{
hid_RprtTitle.Value = Convert.ToString(Request.QueryString["Title"]);
}
hid_unm.Value = Convert.ToString(Session["UName"]);
hid_RprtName.Value = Convert.ToString(Session["Report_Name"]);
hid_CompCode.Value = Convert.ToString(Session["Comp_Code"]);
hid_MonYr.Value = Convert.ToString(Session["MonYr"]);
if (Session["Val"] != null)
{
hid_Val.Value = Convert.ToString(Session["Val"]);
}
else
{
hid_Val.Value = "";
}
LoadReport();
}
if (Session["RptDoc"] != null)
{
CrystalReportViewer1.ReportSource = (ReportDocument)Session["RptDoc"];
CrystalReportViewer1.DataBind();
}
}
}
sayantan_biswas 15-Sep-13 2:11am    
Great solution .Thanks
thatraja 11-Aug-11 2:37am    
Any exceptions you got? If yes then include that too. Put try-catch & try that
Supriya Srivastav 11-Aug-11 2:43am    
Ya i did that,no exceptions are thrown

using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using CrystalDecisions.Shared;
using CrystalDecisions.CrystalReports.Engine;
using CrystalDecisions.CrystalReports;


public partial class Employee_Reports_Forms_frmPrnt_attendance_Summary : System.Web.UI.Page
{
Common cmnsql = new Common();
ReportDocument RptDoc;
DataDefinition df;
protected void Page_Load(object sender, EventArgs e)
{

}

private void LoadReport()
{
try
{
string Rprt_Name = "~\\FAS_Reports\\" + hid_RprtName.Value;
DataTable dtattend = (DataTable)Session["dtattend"];
RptDoc = new ReportDocument();
RptDoc.Load(Server.MapPath(Rprt_Name));
RptDoc.SetDataSource(dtattend);
df = RptDoc.DataDefinition;
RptDoc.Load(Server.MapPath(Rprt_Name));
CrystalReportViewer1.ReportSource = RptDoc;
CrystalReportViewer1.ID = "DownloadedReport";
Session["RptDoc"]= RptDoc;
}
catch (Exception ex)
{
cmnsql.MsgBox1(ex.Message, this);
}
}
private void Page_Init(object sender, EventArgs e)
{
try
{
if (!IsPostBack)
{
Session["RptDoc"] = null;
RptDoc = null;
if (Request.QueryString["Title"] != null)
{
hid_RprtTitle.Value = Convert.ToString(Request.QueryString["Title"]);
}
hid_unm.Value = Convert.ToString(Session["UName"]);
hid_RprtName.Value = Convert.ToString(Session["Report_Name"]);
hid_CompCode.Value = Convert.ToString(Session["Comp_Code"]);
hid_MonYr.Value = Convert.ToString(Session["MonYr"]);
if (Session["Val"] != null)
{
hid_Val.Value = Convert.ToString(Session["Val"]);
}
else
{
hid_Val.Value = "";
}
LoadReport();
}
if (Session["RptDoc"] != null)
{
CrystalReportViewer1.ReportSource = (ReportDocument)Session["RptDoc"];
CrystalReportViewer1.DataBind();
}
}
catch (Exception ex)
{
cmnsql.MsgBox1(ex.Message, this);
}
}
}
thatraja 11-Aug-11 3:29am    
Remove the if (!IsPostBack) & try again in your both previous & current code

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900