Click here to Skip to main content
15,914,222 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I have a web project that has three different web forms that has textboxes on them with a submit button and a print button. I also created a report in Crystal Reports 2013 program. I have added the report to the web project. I also added three more web forms with CrystalReportViewer on them. What I want to do is to setup the print button on the web form that the data is submitted on so it can print out the report without a print preview. So, How can I setup the print button to print out the Crystal Report from Crystal Report Viewer?

This is the web form with the print button. I will show two codes for this form.
This is the .ASPX page code:
ASP.NET
<%@ Page Language="C#" AutoEventWireup="True" Inherits="FinancialProfileFormA" Codebehind="FinancialProfileFormA.aspx.cs" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head  runat="server">
    <title></title>
    <style type="text/css">
        .style1
        {
            font-size: x-large;
            text-align: center;
        }
        .style2
        {
            width: 100%;
        }
        .style5
        {
            width: 20px;
        }
        .style7
        {
            width: 495px;
            font-weight: bold;
        }
        .style9
        {
            width: 20px;
            height: 23px;
        }
        .style10
        {
            width: 495px;
            height: 23px;
            font-weight: bold;
        }
        .style11
        {
            height: 23px;
        }
        .style18
        {
            font-weight: bold;
        }
        .style19
        {
            width: 905px;
            text-align: center;
        }
        .style21
        {
            width: 212px;
            font-weight: bold;
        }
        .style22
        {
            width: 212px;
            height: 23px;
            font-weight: bold;
        }
        .style23
        {
            font-size: small;
        }
        .style24
        {
            font-size: small;
            font-weight: normal;
        }
        .newStyle1
        {
        }
        .style3
        {
            width: 100%;
        }
        .style35
        {
            width: 469px;
            font-weight: bold;
            font-size: large;
        }
        .style36
        {
            width: 469px;
        }
        .style37
        {
            font-size: large;
            width: 424px;
        }
        .style38
        {
            font-size: x-large;
            width: 147px;
        }
        .style40
        {
            width: 645px;
            height: 23px;
            text-align: right;
        }
        .style42
        {
            height: 23px;
            width: 190px;
        }
        .style47
        {
            font-size: large;
            text-align: center;
        }
        .style48
        {
            font-size: xx-large;
        }
        .style49
        {
            font-size: x-large;
        }
        .style50
        {
            width: 585px;
            height: 137px;
        }
        .style51
        {
            font-weight: bold;
            font-size: x-large;
            text-align: center;
        }
        .style52
        {
            width: 670px;
        }
        .style53
        {
            width: 495px;
        }
        .style54
        {
            width: 212px;
        }
        .style55
        {
            font-size: x-large;
            width: 212px;
            text-align: center;
        }
        .style56
        {
            font-weight: bold;
            font-size: large;
            text-align: center;
        }
        .style57
        {
            width: 147px;
        }
    </style>
    <script language="javascript" type="text/javascript">
// <![CDATA[

        function Reset1_onclick() {

        }

// 
    </script>
</head>
<body background="Images/bkg-blu.jpg" bgcolor="#3399ff">
    <form id="form1"  runat="server">
    <div class="style1">
    <asp:Panel ID="Panel1" runat="server">
        <div style="text-align: left">
              <table 
                class="style2">
                <tr>
                    <td style="text-align: center">
                        <img class="style50" src="Images/buildout_header.jpg" /></td>
                </tr>
            </table>
                                     
        </div>
    </asp:Panel>
        
        <span class="style48">
        <br />
        Financial Profile </span></div>
    <br />
                
    <asp:TextBox ID="TextBoxINST_ID" runat="server" Enabled="False" ReadOnly="True" 
        Visible="False"></asp:TextBox>
                
    <asp:TextBox ID="TextBoxaccessLevel" runat="server" style="text-align: center" 
        Visible="False"></asp:TextBox>
                
    <br />
    <table class="style2">
        <tr>
            <td style="text-align: center">
                <asp:Label ID="lblSchool" runat="server" CssClass="style51"></asp:Label>
            </td>
        </tr>
    </table>
    <table class="style2">
        <tr>
            <td class="style52" style="text-align: right">
                <asp:Label ID="lblCity" runat="server" CssClass="style56"></asp:Label>
                ,</td>
            <td>
 <asp:Label ID="lblState" runat="server" CssClass="style56"></asp:Label>
            </td>
        </tr>
        <tr>
            <td class="style52" style="text-align: right">
                 </td>
            <td style="text-align: right">
                <asp:Label ID="lblDate" runat="server" style="font-weight: 700" 
                    Text="Today's Date"></asp:Label>
 
                <asp:TextBox ID="TextBoxDATE" runat="server" 
                    style="font-weight: 700; text-align: center" Width="180px" Enabled="False" 
                    ReadOnly="True"></asp:TextBox>
            </td>
        </tr>
        <tr>
            <td class="style52" style="text-align: right">
                 </td>
            <td style="text-align: right">
                <asp:Label ID="lblTime" runat="server" style="font-weight: 700"></asp:Label>
            </td>
        </tr>
    </table>
    <br />
    <br />
    <table class="style2">
        <tr>
            <td class="style5">
                 </td>
            <td class="style53">
                 </td>
            <td class="style55">
                <asp:Label ID="lblLYEAR" runat="server" style="font-weight: 700"></asp:Label>
            </td>
            <td>
                <span class="style49">           
                <asp:Label ID="lblYEAR" runat="server" style="text-align: center">2013</asp:Label>
                </span></td>
        </tr>
        <tr>
            <td class="style5">
                 </td>
            <td class="style53">
                </td>
        </tr>
    </table>
    <br />
    <table class="style3">
        <tr>
            <td class="style37">
                 </td>
            <td class="style38">
                ^__strong__^     <asp:Label ID="lblLYEAR2" runat="server"></asp:Label>
                </strong__^</td>
            <td class="style35">
                ^__strong style="font-size: x-large"__^           
                <asp:Label ID="lblYEAR2" runat="server">2013</asp:Label>
                </td>
        </tr>
        <tr>
            <td class="style37">
                 </td>
            <td class="style57">
                 </td>
            <td class="style36">
                 </td>
        </tr>
        <tr>
            <td class="style37">
                ^__b__^Total Assets</td>
            <td class="style57">
                <asp:TextBox ID="TextBoxLYTA" runat="server" Width="180px" Enabled="False" 
                    ReadOnly="True"></asp:TextBox>
            </td>
            <td class="style36">
                <asp:TextBox ID="TextBoxTA" runat="server" Width="180px">0</asp:TextBox>
                <asp:RequiredFieldValidator ID="RequiredFieldValidator30" runat="server" 
                    ControlToValidate="TextBoxTA" 
                    ErrorMessage="You Must Enter A Number For This Field!!!" ForeColor="Red"></asp:RequiredFieldValidator>
            </td>
        </tr>
        <tr>
            <td class="style37">
                ^__b__^Total Liabilities</td>
            <td class="style57">
                <asp:TextBox ID="TextBoxLYTL" runat="server" Width="180px" Enabled="False" 
                    ReadOnly="True"></asp:TextBox>
            </td>
            <td class="style36">
                <asp:TextBox ID="TextBoxTL" runat="server" Width="180px" AutoPostBack="True" 
                    ontextchanged="TextBoxTL_TextChanged">0</asp:TextBox>
                <asp:RequiredFieldValidator ID="RequiredFieldValidator31" runat="server" 
                    ControlToValidate="TextBoxTL" 
                    ErrorMessage="You Must Enter A Number For This Field!!!" ForeColor="Red"></asp:RequiredFieldValidator>
            </td>
        </tr>
        <tr>
            <td class="style37">
                ^__strong__^Total Net Assets</td>
            <td class="style57">
                 </td>
            <td class="style36">
                <asp:TextBox ID="TextBoxTNA" runat="server" Width="180px" Enabled="False" 
                    ReadOnly="True"></asp:TextBox>
            </td>
        </tr>
        <tr>
            <td class="style37">
                ^__b__^Nonexpendable/Permanently Restricted Net Assets</td>
            <td class="style57">
                <asp:TextBox ID="TextBoxLYNPRNA" runat="server" Width="180px" Enabled="False" 
                    ReadOnly="True"></asp:TextBox>
            </td>
            <td class="style36">
                <asp:TextBox ID="TextBoxNPRNA" runat="server" Width="180px">0</asp:TextBox>
                <asp:RequiredFieldValidator ID="RequiredFieldValidator32" runat="server" 
                    ControlToValidate="TextBoxNPRNA" 
                    ErrorMessage="You Must Enter A Number For This Field!!!" ForeColor="Red"></asp:RequiredFieldValidator>
            </td>
        </tr>
        <tr>
            <td class="style37">
                ^__b__^Expendable/Temporarily Restricted Net Assets</td>
            <td class="style57">
                <asp:TextBox ID="TextBoxLYETRNA" runat="server" Width="180px" Enabled="False" 
                    ReadOnly="True"></asp:TextBox>
            </td>
            <td class="style36">
                <asp:TextBox ID="TextBoxETRNA" runat="server" Width="180px">0</asp:TextBox>
                <asp:RequiredFieldValidator ID="RequiredFieldValidator33" runat="server" 
                    ControlToValidate="TextBoxETRNA" 
                    ErrorMessage="You Must Enter A Number For This Field!!!" ForeColor="Red"></asp:RequiredFieldValidator>
            </td>
        </tr>
        <tr>
            <td class="style37">
                ^__b__^Total Unrestricted Net Assets <span class="style23">(Unrestricted net assets 
                Plus capital assets, net)</span></td>
            <td class="style57">
                <asp:TextBox ID="TextBoxLYTUNA" runat="server" Width="180px" Enabled="False" 
                    ReadOnly="True"></asp:TextBox>
            </td>
            <td class="style36">
                <asp:TextBox ID="TextBoxTUNA" runat="server" Width="180px" AutoPostBack="True" 
                    ontextchanged="TextBoxTUNA_TextChanged">0</asp:TextBox>
                <asp:RequiredFieldValidator ID="RequiredFieldValidator34" runat="server" 
                    ControlToValidate="TextBoxTUNA" 
                    ErrorMessage="You Must Enter A Number For This Field!!!" ForeColor="Red"></asp:RequiredFieldValidator>
            </td>
        </tr>
        <tr>
            <td class="style37">
                ^__b__^Total Revenue</td>
            <td class="style57">
                <asp:TextBox ID="TextBoxLYTR" runat="server" Width="180px" Enabled="False" 
                    ReadOnly="True"></asp:TextBox>
            </td>
            <td class="style36">
                <asp:TextBox ID="TextBoxTR" runat="server" Width="180px">0</asp:TextBox>
                <asp:RequiredFieldValidator ID="RequiredFieldValidator35" runat="server" 
                    ControlToValidate="TextBoxTR" 
                    ErrorMessage="You Must Enter A Number For This Field!!!" ForeColor="Red"></asp:RequiredFieldValidator>
            </td>
        </tr>
        <tr>
            <td class="style37">
                ^__b__^Tuition and Fees, Net</td>
            <td class="style57">
                <asp:TextBox ID="TextBoxLYTFN" runat="server" Width="180px" Enabled="False" 
                    ReadOnly="True"></asp:TextBox>
            </td>
            <td class="style36">
                <asp:TextBox ID="TextBoxTFN" runat="server" Width="180px">0</asp:TextBox>
                <asp:RequiredFieldValidator ID="RequiredFieldValidator36" runat="server" 
                    ControlToValidate="TextBoxTFN" 
                    ErrorMessage="You Must Enter A Number For This Field!!!" ForeColor="Red"></asp:RequiredFieldValidator>
            </td>
        </tr>
        <tr>
            <td class="style37">
                ^__b__^Current Debt</td>
            <td class="style57">
                <asp:TextBox ID="TextBoxLYCD" runat="server" Width="180px" Enabled="False" 
                    ReadOnly="True"></asp:TextBox>
            </td>
            <td class="style36">
                <asp:TextBox ID="TextBoxCD" runat="server" Width="180px">0</asp:TextBox>
                <asp:RequiredFieldValidator ID="RequiredFieldValidator37" runat="server" 
                    ControlToValidate="TextBoxCD" 
                    ErrorMessage="You Must Enter A Number For This Field!!!" ForeColor="Red"></asp:RequiredFieldValidator>
            </td>
        </tr>
        <tr>
            <td class="style37">
                ^__b__^Long-term Debt</td>
            <td class="style57">
                <asp:TextBox ID="TextBoxLYLTD" runat="server" Width="180px" Enabled="False" 
                    ReadOnly="True"></asp:TextBox>
            </td>
            <td class="style36">
                <asp:TextBox ID="TextBoxLTD" runat="server" Width="180px">0</asp:TextBox>
                <asp:RequiredFieldValidator ID="RequiredFieldValidator38" runat="server" 
                    ControlToValidate="TextBoxLTD" 
                    ErrorMessage="You Must Enter A Number For This Field!!!" ForeColor="Red"></asp:RequiredFieldValidator>
            </td>
        </tr>
        <tr>
            <td class="style37">
                ^__b__^Total Net Assets</td>
            <td class="style57">
                <asp:TextBox ID="TextBoxLYTNA" runat="server" Width="180px" Enabled="False" 
                    ReadOnly="True"></asp:TextBox>
            </td>
            <td class="style36">
                <asp:TextBox ID="TextBoxTNA2" runat="server" Width="180px" Enabled="False" 
                    ReadOnly="True"></asp:TextBox>
                <asp:CompareValidator ID="CompareValidator1" runat="server" 
                    ControlToCompare="TextBoxTNA" ControlToValidate="TextBoxTNA2" 
                    ErrorMessage="The Entry Does Not Match Each Other!!" ForeColor="Red"></asp:CompareValidator>
            </td>
        </tr>
    </table>
    <br />
    <table class="style3">
        <tr>
            <td class="style40">
                ^__strong__^Name</td>
            <td class="style42">
                <asp:TextBox ID="TextBoxFullN" runat="server" Width="180px"></asp:TextBox>
            </td>
            <td>
                <asp:RequiredFieldValidator ID="RequiredFieldValidator3" runat="server" 
                    ControlToValidate="TextBoxFullN" ErrorMessage="Please Give Your Full Name!!!" 
                    ForeColor="Red" CssClass="style18"></asp:RequiredFieldValidator>
            </td>
        </tr>
        <tr>
            <td class="style40">
                ^__strong__^Title</td>
            <td class="style42">
                <asp:TextBox ID="TextBoxTitle" runat="server" Width="180px"></asp:TextBox>
            </td>
            <td>
                <asp:RequiredFieldValidator ID="RequiredFieldValidator4" runat="server" 
                    ControlToValidate="TextBoxTitle" ErrorMessage="Please Give Your Title!!!" 
                    ForeColor="Red" CssClass="style18"></asp:RequiredFieldValidator>
            </td>
        </tr>
        <tr>
            <td class="style40">
                ^__strong__^Institution</td>
            <td class="style42">
                <asp:Label ID="lblSchool2" runat="server"></asp:Label>
            </td>
            <td>
                 </td>
        </tr>
        <tr>
            <td class="style40">
                ^__strong__^Mailing ^__strong>Address</td>
            <td class="style42">
                <asp:TextBox ID="TextBoxMA" runat="server" Width="180px"></asp:TextBox>
            </td>
            <td>
                <asp:RequiredFieldValidator ID="RequiredFieldValidator6" runat="server" 
                    ControlToValidate="TextBoxMA" 
                    ErrorMessage="Please Give Your Mailing Address!!!" ForeColor="Red" 
                    CssClass="style18"></asp:RequiredFieldValidator>
            </td>
        </tr>
        <tr>
            <td class="style40">
                ^__strong>Telephone Number</td>
            <td class="style42">
                <asp:TextBox ID="TextBoxTN" runat="server" Width="180px"></asp:TextBox>
            </td>
            <td>
                <asp:RequiredFieldValidator ID="RequiredFieldValidator7" runat="server" 
                    ControlToValidate="TextBoxTN" 
                    ErrorMessage="Please Give Your Telephone Number!!!" ForeColor="Red" 
                    CssClass="style18"></asp:RequiredFieldValidator>
            </td>
        </tr>
        <tr>
            <td class="style40">
                ^__strong>Fax Number</td>
            <td class="style42">
                <asp:TextBox ID="TextBoxFN" runat="server" Width="180px"></asp:TextBox>
            </td>
            <td>
                <asp:RequiredFieldValidator ID="RequiredFieldValidator8" runat="server" 
                    ControlToValidate="TextBoxFN" ErrorMessage="Please Give Your  Fax Number!!!" 
                    ForeColor="Red" CssClass="style18"></asp:RequiredFieldValidator>
            </td>
        </tr>
        <tr>
            <td class="style40">
                ^__strong>Email Address</td>
            <td class="style42">
                <asp:TextBox ID="TextBoxEA" runat="server" Width="180px"></asp:TextBox>
            </td>
            <td>
                <asp:RequiredFieldValidator ID="RequiredFieldValidator9" runat="server" 
                    ControlToValidate="TextBoxEA" ErrorMessage="Please Give Your Email Address!!!" 
                    ForeColor="Red" CssClass="style18"></asp:RequiredFieldValidator>
            </td>
        </tr>
    </table>
    <br />
    <br />
    <table class="style2">
        <tr>
            <td class="style19">
                                                                
                <asp:Button ID="ButtonSubmit" runat="server" onclick="ButtonSubmit_Click" 
                    Text="Submit" Width="100px" style="text-align: center" />
            </td>
            <td>
                <asp:Button ID="ButtonPrint" runat="server" onclick="ButtonPrint_Click" Text="Print" Width="100px" />
            </td>
        </tr>
    </table>
    </form>
    </body>
</html>


This is the Behind code for that page:
C#
using System;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Text;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Configuration;
using System.Drawing.Printing;
using System.IO;
using System.Web.SessionState;
using CrystalDecisions.CrystalReports.Engine;
using CrystalDecisions.Shared;

public partial class FinancialProfileFormA : System.Web.UI.Page
{

    protected void Page_Load(object sender, EventArgs e)
    {
     TextBoxINST_ID.Text = Session["inst_id"].ToString();
    }
protected void ButtonSubmit_Click(object sender, EventArgs e)
    {

        SqlConnection con = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["HotConnectionString"].ConnectionString);
        con.Open();
        SqlCommand cmd = new SqlCommand("Insert into Table22 (INST_ID, TOTAL_REVE, DATE, FINYR, INSTRUCTIO, RESEARCH, PUBLIC_SER, ACADEMIC_S, STUDENT_SE, INSTITUTIO, PHYSICAL_P, SCHOLARSHI, AUXILIARY_, HOSPITALS, INDEPENDEN, OTHEREXP, TOTASSETS, TOTLIABILITY, NoNEXPPERMRESASSETS, EXPENDABLE, UNRNETASSETS, TOTALREV, TUITFEES, CURRDEBT, LONGTERMDEBT, TOTALNETASSETS) values (@INST_ID, @TOTAL_REVE, @DATE, @FINYR, @INSTRUCTIO, @RESEARCH, @PUBLIC_SER, @ACADEMIC_S, @STUDENT_SE, @INSTITUTIO, @PHYSICAL_P, @SCHOLARSHI, @AUXILIARY_, @HOSPITALS, @INDEPENDEN, @OTHEREXP, @TOTASSETS, @TOTLIABILITY, @NoNEXPPERMRESASSETS, @EXPENDABLE, @UNRNETASSETS, @TOTALREV, @TUITFEES, @CURRDEBT, @LONGTERMDEBT, @TOTALNETASSETS)Insert into Table23 (INST_ID, TOTAL_REVE, DATE, FINYR, INSTRUCTIO, RESEARCH, PUBLIC_SER, ACADEMIC_S, STUDENT_SE, INSTITUTIO, PHYSICAL_P, SCHOLARSHI, AUXILIARY_, HOSPITALS, INDEPENDEN, OTHEREXP, TOTASSETS, TOTLIABILITY, NoNEXPPERMRESASSETS, EXPENDABLE, UNRNETASSETS, TOTALREV, TUITFEES, CURRDEBT, LONGTERMDEBT, TOTALNETASSETS) values (@INST_ID, @TOTAL_REVE, @DATE, @FINYR, @INSTRUCTIO, @RESEARCH, @PUBLIC_SER, @ACADEMIC_S, @STUDENT_SE, @INSTITUTIO, @PHYSICAL_P, @SCHOLARSHI, @AUXILIARY_, @HOSPITALS, @INDEPENDEN, @OTHEREXP, @TOTASSETS, @TOTLIABILITY, @NoNEXPPERMRESASSETS, @EXPENDABLE, @UNRNETASSETS, @TOTALREV, @TUITFEES, @CURRDEBT, @LONGTERMDEBT, @TOTALNETASSETS)", con);
        cmd.CommandType = CommandType.Text;

        cmd.Parameters.AddWithValue("@INST_ID", TextBoxINST_ID.Text);
        cmd.Parameters.AddWithValue("@TOTAL_REVE", TextBoxTROA.Text);
        cmd.Parameters.AddWithValue("@INSTRUCTIO", TextBoxInstr.Text);
        cmd.Parameters.AddWithValue("@RESEARCH", TextBoxRes.Text);
        cmd.Parameters.AddWithValue("@PUBLIC_SER", TextBoxPubS.Text);
        cmd.Parameters.AddWithValue("@ACADEMIC_S", TextBoxAcad.Text);
        cmd.Parameters.AddWithValue("@STUDENT_SE", TextBoxStudS.Text);
        cmd.Parameters.AddWithValue("@INSTITUTIO", TextBoxInstiS.Text);
        cmd.Parameters.AddWithValue("@PHYSICAL_P", TextBoxOperM.Text);
        cmd.Parameters.AddWithValue("@SCHOLARSHI", TextBoxSFEDA.Text);
        cmd.Parameters.AddWithValue("@AUXILIARY_", TextBoxAuxE.Text);
        cmd.Parameters.AddWithValue("@HOSPITALS", TextBoxHosS.Text);
        cmd.Parameters.AddWithValue("@INDEPENDEN", TextBoxIndeO.Text);
        cmd.Parameters.AddWithValue("@OTHEREXP", TextBoxOED.Text);
        cmd.Parameters.AddWithValue("@TOTASSETS", TextBoxTA.Text);
        cmd.Parameters.AddWithValue("@TOTLIABILITY", TextBoxTL.Text);
        cmd.Parameters.AddWithValue("@NoNEXPPERMRESASSETS", TextBoxNPRNA.Text);
        cmd.Parameters.AddWithValue("@EXPENDABLE", TextBoxETRNA.Text);
        cmd.Parameters.AddWithValue("@UNRNETASSETS", TextBoxTUNA.Text);
        cmd.Parameters.AddWithValue("@TOTALREV", TextBoxTR.Text);
        cmd.Parameters.AddWithValue("@TUITFEES", TextBoxTFN.Text);
        cmd.Parameters.AddWithValue("@CURRDEBT", TextBoxCD.Text);
        cmd.Parameters.AddWithValue("@LONGTERMDEBT", TextBoxLTD.Text);
        cmd.Parameters.AddWithValue("@FINYR", lblYEAR.Text);
        cmd.Parameters.AddWithValue("@DATE", TextBoxDATE.Text);
        cmd.Parameters.AddWithValue("@TOTALNETASSETS", TextBoxTNA.Text);


        cmd.ExecuteNonQuery();
        ScriptManager.RegisterStartupScript(this, this.GetType(), "script", "alert('You Have Successfully Submitted the Financial Profile');", true);
con.Close();

protected void ButtonPrint_Click(object sender, EventArgs e)
    {
        
    }
}


Here is the .ASPX code for the Crystal Report Viewer:
ASP.NET
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="ReportFormA.aspx.cs" Inherits="SACSCOCLogin1._1.ReportFormA" %>

<%@ Register assembly="CrystalDecisions.Web, Version=13.0.2000.0, Culture=neutral, PublicKeyToken=692fbea5521e1304" namespace="CrystalDecisions.Web" tagprefix="CR" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head  runat="server">
    <title></title>
</head>
<body>
    <form id="form1"  runat="server">
    <div>
    
        <CR:CrystalReportViewer ID="CrystalReportViewer1"  runat="server" 
            AutoDataBind="True" EnableDatabaseLogonPrompt="False" 
            GroupTreeImagesFolderUrl="" Height="1202px" 
            ReportSourceID="CrystalReportSourceA" ToolbarImagesFolderUrl="" 
            ToolPanelView="None" ToolPanelWidth="200px" Width="1104px" />
        <CR:CrystalReportSource ID="CrystalReportSourceA"  runat="server">
            <Report FileName="FormAReport.rpt">
            </Report>
        </CR:CrystalReportSource>
    
    </div>
    </form>
</body>
</html>


The Behind Code for that page:

C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using CrystalDecisions.CrystalReports.Engine;
using CrystalDecisions.Shared;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;

namespace SACSCOCLogin1._1
{
    public partial class ReportFormA : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            CrystalReportViewer1.Visible = false;
        }
    }
}
Posted

1 solution

You could export the report to PDF behind the scenes (i.e. through .NET code) as it's described here but instead of using that solution, you could embed some javascript print function into the PDF file using PDFSharp (http://stackoverflow.com/a/17732531[^]) to get it printed directly when the file is opened. With this approach you avoid print preview and the printing should work with any browser.
 
Share this answer
 

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