Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
Hello all,
 
First let me say I know that there are probably hundreds of postings on the net that refer to asp and CR. I have looked for about a week trying things to no avail. If you have a web page that you think will help I would be very happy to check it out, but I have google'd this subject over and over again.
 
I am working on a asp/C# project that will take any crystal report and display it on a web page, that part is simple enough. In this project I am looking for simplicity, something that will run possible for days/weeks on end on any type of browser or OS. I am using CR XIR2, asp.net 4.0 and VS2010. My project will display a report and refresh the data and report on a set time period. I do not have a dataset in my project. The report connects directly to the SQL server and pulls the data. I have gotten the automated page refresh working with some javascript on the asp page, but I am having trouble automating the next page display. I am looking to rotate through the pages every two minutes or so and refresh the entire report every 10 mins or so. Here is my asp page:
 
<%@ Page Language="C#" AutoEventWireup="true"  CodeFile="Default.aspx.cs" Inherits="_Default" %>
<%@ Register TagPrefix="CR" Namespace="CrystalDecisions.Web" Assembly="CrystalDecisions.Web, Version=13.0.2000.0, Culture=neutral, PublicKeyToken=692fbea5521e1304" %>
 
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>Untitled Page</title>
    <script type="text/javascript">
        function timeClick() {
            var t = setTimeout("clickButton()", 180000);
        }
 
        function clickButton() {
            var button = document.getElementById('RefreshButton');
            button.click();
            timeClick();
        }
</script>
<script type="text/C#"  runat="server">
    public void CommandBtn_Click(object sender, CommandEventArgs e)
    {
        CrystalReportViewer1.RefreshReport();
    }
</script>
</head>
<body>
<script type="text/javascript">
    window.onload = timeClick;
</script>
    <form id="form1" runat="server">
    <div style="display: none;">
        <asp:Button ID="RefreshButton" runat="server" onCommand="CommandBtn_Click" />
    </div>
    <div>
        <CR:CrystalReportViewer ID="CrystalReportViewer1"  runat="server" AutoDataBind="True"
            Height="1039px" ReportSourceID="CrystalReportSource1" Width="901px" DisplayStatusbar="False" 
            HasDrilldownTabs="False" HasToggleGroupTreeButton="False" 
            HasToggleParameterPanelButton="False" ToolPanelView="None" />
        <CR:CrystalReportSource ID="CrystalReportSource1"  runat="server">
            <Report FileName="CrystalReport1.rpt">
            </Report>
        </CR:CrystalReportSource>
    
    </div>
    </form>
</body>
</html>
 

 

 

And here is my C# code behind:
 
using System;
using System.Data;
using System.Configuration;
 
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.Web;
 
public partial class _Default : System.Web.UI.Page 
{
    private ReportDocument rpt;
 
    private void Page_Init(object sender, EventArgs e)
    {
        ConfigureCrystalReports();
    }
    protected void Page_Load(object sender, EventArgs e)
    {
 
    }
    private void ConfigureCrystalReports()
    {
        rpt = new ReportDocument();
        string reportPath = Server.MapPath("CrystalReport1.rpt");
        rpt.Load(reportPath);
        ConnectionInfo connectionInfo = new ConnectionInfo();
        connectionInfo.DatabaseName = "******";
        connectionInfo.UserID = "*****";
        connectionInfo.Password = "*****";
        SetDBLogonForReport(connectionInfo, rpt);
        CrystalReportViewer1.ReportSource = rpt;
    }
    private void SetDBLogonForReport(ConnectionInfo connectionInfo, ReportDocument reportDocument)
    {
        Tables tables = reportDocument.Database.Tables;
        foreach (CrystalDecisions.CrystalReports.Engine.Table table in tables)
        {
            TableLogOnInfo tableLogonInfo = table.LogOnInfo;
            tableLogonInfo.ConnectionInfo = connectionInfo;
            table.ApplyLogOnInfo(tableLogonInfo);
        }
    }
}
 

I have left out the many different approaches I have attempted. I hope someone can help.... Thanks in advance.
Posted 18-Jan-13 9:27am
Comments
Adam R Harris at 18-Jan-13 15:15pm
   
I think you are on the right track with the RefreshButton stuff. You are just going to have to find the Next Page button and essentially do the exact same thing that you are doing for the Refresh. Open the page in IE or Chrome and inspect the down using the developer tools to find the actually button name and just invoke the click like you are for the Refresh.
garrettchatt at 18-Jan-13 16:02pm
   
I have looked at the element id in the code view of the page during a preview through VS. The element is labeled "IconImg_CrystalReportViewer1_toptoolbar_nextPg". I have tried that and "nextPg" with the same setup as the clickButton function and calling it but I haven't got either to work...
Adam R Harris at 18-Jan-13 17:54pm
   
I'll try and take a look at this over the weekend for you, i dont have a project here at work that mirrors what you are attempting to do so i'll have to set something up at home.

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

I think this is it but I won't be able to test it until Monday...
Add these code snippets at the appropriate places:
 
<script type="text/javascript">
function nextPg_timeClick() {
            var i = setTimeout("nextPg_Click()", 1800);
        }
        function nextPg_Click() {
            var button1 = document.getElementById('nextPg');
            button1.click();
            nextPg_timeClick();
        }
</script>
<script type="text/C#"  runat="server">
    public void Commandnav_Click(object sender, CommandEventArgs e)
    {
        CrystalReportViewer1.ShowNextPage();
    }
</script>
 

<asp:button id="nextPg" runat="server" oncommand="Commandnav_Click" 
  Permalink  
v4

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

  Print Answers RSS
0 DamithSL 390
1 Maciej Los 217
2 OriginalGriff 213
3 BillWoodruff 130
4 Garth J Lancaster 90
0 OriginalGriff 7,953
1 DamithSL 6,139
2 Sergey Alexandrovich Kryukov 5,449
3 Maciej Los 5,293
4 Kornfeld Eliyahu Peter 4,539


Advertise | Privacy | Mobile
Web04 | 2.8.141223.1 | Last Updated 18 Jan 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100