Click here to Skip to main content
15,885,278 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I have a web form that has a print button o it that when clicked that print button opens CRV in a new window. I want to change it to where the report opens in a new tab in the same web browser. How can I get this to work?

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" HasDrilldownTabs="False" 
            HasToggleGroupTreeButton="False" HasToggleParameterPanelButton="False" 
            HasCrystalLogo="False" HasDrillUpButton="False" HasExportButton="False" 
            HasGotoPageButton="False" HasPageNavigationButtons="False" 
            HasSearchButton="False" HasZoomFactorList="False" />
        <CR:CrystalReportSource ID="CrystalReportSourceA"  runat="server">
            <Report FileName="FormAReport.rpt">
            </Report>
        </CR:CrystalReportSource>
    
    </div>
    <p>
         </p>
    <p>
         </p>
    <p>
         </p>
    <p>
         </p>
    <p>
        <asp:TextBox ID="TextBoxINST_ID" runat="server" Enabled="False" ReadOnly="True" 
            Visible="False"></asp:TextBox>
    </p>
    <p>
         </p>
    </form>
</body>
</html>


Here is the code:
C#
using System;
using System.Collections.Generic;
using System.Collections;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using CrystalDecisions.Web;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.WebControls;
using CrystalDecisions.CrystalReports.Engine;
using CrystalDecisions.Shared;
using CrystalDecisions.Windows.Forms;
using CrystalDecisions.ReportSource;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using System.Xml.Linq;
using System.Web.SessionState;
using CrystalDecisions.ReportAppServer;
using System.Drawing;
using System.Drawing.Printing;



namespace SACSCOCLogin1._1
{
    public partial class ReportFormA : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            SqlConnection con = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["HotConnectionString"].ConnectionString);
            con.Open();
            TextBoxUSERID.Text = Session["USERID"].ToString();
            CrystalReportViewer1.Visible = true;

            ReportDocument CrystalReport = new ReportDocument();
            ParameterField paramField = new ParameterField();
            ParameterFields paramFields = new ParameterFields();
            ParameterDiscreteValue paramDiscreteValue = new ParameterDiscreteValue();

            paramField.Name = "USERID";
            paramField.CurrentValues.Clear();
            paramDiscreteValue = new ParameterDiscreteValue();
            paramDiscreteValue.Value = TextBoxUSERID.Text;
            paramFields.Add(paramField);
            CrystalReportViewer1.ParameterFieldInfo = paramFields;

            CrystalReport.Load(Server.MapPath("FormAReport.rpt"));
            string sessiontype = TextBoxINST_ID.Text;
            CrystalReport.SetParameterValue("USERID", TextBoxUSERID.Text);

            string sessionid = TextBoxUSERID.Text;
            CrystalReport.SetParameterValue("USERID", TextBoxUSERID.Text);
            CrystalReportViewer1.ReportSource = CrystalReport;
            con.Close();

        }
    }
}


Here is the print button code:

C#
protected void ButtonPrint_Click(object sender, EventArgs e)
    {
        TextBoxUSERID.Text = Session["USERID"].ToString();
        ClientScript.RegisterStartupScript(this.GetType(), "onclick", "<script language=javascript>window.open('ReportFormA.aspx','PrintMe','height=650px,width=950px,scrollbars=1');</script>");
    }
Posted
Updated 3-Feb-15 4:11am
v2

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