4
votes

I am using visual studio 2010 and crystal report 13.0

The report viewer displays the first page properly. But the next page button is not working. If i click on next page button then it shows loading message and stays there only.None of the report viewer controls are working.

please help me out

4
is this happening on local machine or server. You could have a look at the following link. stackoverflow.com/questions/53347/…aMazing

4 Answers

9
votes

I found the solution. Manually add the Page_Init() event and wire it up in the InitializeCompnent() with

this.Init += new System.EventHandler(this.Page_Init).

Move the contents of Page_Load to Page_Init().

Add if (!IsPostBack) condition in PageInIt.

protected void Page_Init(object sender, EventArgs e)
{

        if (!IsPostBack)
        {
             ReportDocument crystalReportDocument = new ReportDocumment();
             crystalReportDocument.SetDataSource(DataTableHere);
             _reportViewer.ReportSource = crystalReportDocument;
             Session["ReportDocument"] = crystalReportDocument;
        }
        else
        {
              ReportDocument doc = (ReportDocument)Session["ReportDocument"];
              _reportViewer.ReportSource = doc;
        }
   }
1
votes

Instead of manually identifying the moment to bind, you could use the CrystalReportViewer AutoDataBind property in combination with the DataBinding event.

Autobind definition:

    // Summary:
    //     Boolean. Gets or sets whether automatic data binding to a report source is
    //     used. If the value is set to True, the DataBind() method is called after
    //     OnInit() or Page_Init().
    [Category("Data")]
    [DefaultValue(false)]
    [DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)]
    public bool AutoDataBind { get; set; }

You could use this property in the following manner:

In the ASPX:

<CR:CrystalReportViewer ID="_reportViewer" runat="server" AutoDataBind="true" OnDataBinding="_reportViewer_DataBinding" />

And in the ASPX.CS:

protected void _reportViewer_DataBinding(object sender, EventArgs e)
{
    if (!IsPostBack)
    {
        ReportDocument crystalReportDocument = new ReportDocumment();
        crystalReportDocument.SetDataSource(DataTableHere);
        _reportViewer.ReportSource = crystalReportDocument;
        Session["ReportDocument"] = crystalReportDocument;
    }
    else
    {
        ReportDocument doc = (ReportDocument)Session["ReportDocument"];
        _reportViewer.ReportSource = doc;
    }
}
0
votes

Done! Shift your Page load Event to Page Init Event.

enter image description here

0
votes
 protected void Page_Load(object sender, EventArgs e)
 {
     if (IsPostBack)
     {
           int pageIndex =((CrystalDecisions.Shared.PageRequestContext)  
            CrystalReportViewer1.RequestContext).PageNumber;

           //Bind Report with filter and datasource

           string ControID = GetPostBackControlName(this);
          //get and check Crystal Report Navigation button event after Bind Report

           if (ControID == null)
           {  
              ((CrystalDecisions.Shared.PageRequestContext)
              CrystalReportViewer1.RequestContext).PageNumber = pageIndex;      
            }
      }
 }

 public string GetPostBackControlName(Page Page)
    {
        Control control = null;

        string ctrlname = Page.Request.Params["__EVENTTARGET"];
        if (ctrlname != null && ctrlname != String.Empty)
        {
            control = Page.FindControl(ctrlname);
        }
        else
        {
            string ctrlStr = String.Empty;
            Control c = null;
            foreach (string ctl in Page.Request.Form)
            {
                if (ctl.EndsWith(".x") || ctl.EndsWith(".y"))
                {
                    ctrlStr = ctl.Substring(0, ctl.Length - 2);
                    c = Page.FindControl(ctrlStr);
                }
                else
                {
                    c = Page.FindControl(ctl);
                }
                if (c is System.Web.UI.WebControls.Button ||
                         c is System.Web.UI.WebControls.ImageButton)
                {
                    control = c;
                    break;
                }
            }
        }
        if (control == null)
        {
            return null;
        }
        else
        {
            return control.ID;
        }
    }