cancel
Showing results for 
Search instead for 
Did you mean: 

Adding crsytall report is disabling DropDownList2_SelectedIndexChanged trigger event

assay
Member
0 Kudos

I have asp.net webform page that loads report. On this page I have several DropDownLists where at Page_Load only one is visible and populated with data from SQL Server and the others are disabled. When SelectedIndex_Changed, the other DropDownLists are enabled and populated with data(Casacading DropDownList). This works well in VS 2019 but after deploying to production (IIS 10) when I select any Item from the first DropDownList nothing happens.But if I click the submit button the second DropDownList is enabled and populated.I have understood this is happening because of the CrystalReport that I added for the report because when I remove it it is working perfectly.I am using Version=13.0.4000.0. This is my first time developing an app and I have been stuck for days because of this problem any help would be appreciated.

here is a sample of my code

aspx.cs file

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

namespace CashFlowMS.Report
{
public partial class rptVweTransactionForAccountant : System.Web.UI.Page
{
private string connectionString = Properties.Settings.Default.connection;
private SqlConnection _sqlConnection;
private string _queryString;
private SqlDataAdapter _sqlDataAdapter;
private DataSet _dataSet;

protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{


drpTransactionType.AppendDataBoundItems = true;
drpTransactionType.Items.Clear();
drpTransactionType.Enabled = true;
drpTransactionType.Items.Insert(0, new ListItem("--select report type--", "-1"));

drpBank.AppendDataBoundItems = true;
drpBank.Items.Clear();
drpBank.Items.Insert(0, new ListItem("--select bank--", "-1"));
drpBank.Enabled = true;

drpBranch.Items.Clear();
drpBranch.Items.Insert(0, new ListItem("--select branch--", "-1"));
drpBranch.Enabled = false;


using (_sqlConnection = new SqlConnection(connectionString))
{
// fill transaction type dropdown
_queryString = "select * from tblTransactionType";
_sqlDataAdapter = new SqlDataAdapter(_queryString, _sqlConnection);
_dataSet = new DataSet();
_sqlDataAdapter.Fill(_dataSet); // fill dataset

drpTransactionType.DataTextField = _dataSet.Tables[0].Columns["Type"].ToString(); // text field name of table dispalyed in dropdown
drpTransactionType.DataValueField = _dataSet.Tables[0].Columns["Id"].ToString(); // to retrive specific textfield name
drpTransactionType.DataSource = _dataSet.Tables[0]; //assigning datasource to the dropdownlist
drpTransactionType.DataBind(); //binding dropdownlist


// fill bank dropdown
_queryString = "select * from tblBank";
_sqlDataAdapter = new SqlDataAdapter(_queryString, _sqlConnection);
_dataSet = new DataSet();
_sqlDataAdapter.Fill(_dataSet);

drpBank.DataTextField = _dataSet.Tables[0].Columns["Name"].ToString();
drpBank.DataValueField = _dataSet.Tables[0].Columns["Id"].ToString();
drpBank.DataSource = _dataSet.Tables[0];
drpBank.DataBind();


}

}
}

protected void drpBank_SelectedIndexChanged(object sender, EventArgs e)
{
if (drpBank.SelectedIndex == 0)
{
drpBranch.Enabled = false;
drpBranch.SelectedIndex = 0;
}
else
{
drpBranch.AppendDataBoundItems = true;
drpBranch.Enabled = true;
drpBranch.Items.Clear();
drpBranch.Items.Insert(0, new ListItem("--select branch--", "-1"));

var bankValue = Convert.ToInt32(drpBank.SelectedValue);


using (_sqlConnection = new SqlConnection(connectionString))
{
_queryString = "SELECT * FROM tblBranch WHERE Bank_Id = '" + bankValue + "' ";

_sqlDataAdapter = new SqlDataAdapter(_queryString, _sqlConnection);
_dataSet = new DataSet();
_sqlDataAdapter.Fill(_dataSet);

drpBranch.DataTextField = _dataSet.Tables[0].Columns["Name"].ToString();
drpBranch.DataValueField = _dataSet.Tables[0].Columns["Id"].ToString();
drpBranch.DataSource = _dataSet.Tables[0];
drpBranch.DataBind();
}

}
}

protected void btnTransactionHistory_Click(object sender, EventArgs e)
{

if (drpTransactionType.SelectedIndex > 0 && drpBranch.SelectedIndex > 0 && drpBank.SelectedIndex > 0)
{
if (!string.IsNullOrWhiteSpace(txtStartDate.Text) && !string.IsNullOrWhiteSpace(txtEndDate.Text))
{
DateTime startDate = Convert.ToDateTime(txtStartDate.Text);
DateTime endDate = Convert.ToDateTime(txtEndDate.Text);

try
{
using (_sqlConnection = new SqlConnection(connectionString))
{
_queryString = "SELECT * FROM View_Transaction where Branch = '" +
drpBranch.SelectedItem.Text + "' AND Bank = '" +
drpBank.SelectedItem.Text +
"' AND Acc_Type = 'Birr' AND Trans_Type = '" +
drpTransactionType.SelectedItem.Text + "' AND Date BETWEEN '" + startDate + "' AND '" + endDate + "'";

_sqlDataAdapter = new SqlDataAdapter(_queryString, _sqlConnection);
_dataSet = new DataSet();
_sqlDataAdapter.Fill(_dataSet);

var report = new ReportDocument();
report.Load(Server.MapPath("~/Report/rptTransactionHistory.rpt"));
report.Refresh();
report.SetDataSource(_dataSet.Tables[0]);

cryslRptVwrTransactionHistoryAccountant.ReportSource = report;
report.ExportToHttpResponse(ExportFormatType.PortableDocFormat, Response, false, "Branch's Transaction History ");
report.Close();
report.Dispose();
Response.End();
cryslRptVwrTransactionHistoryAccountant.RefreshReport();
}
}

catch (Exception ex)
{
Page.ClientScript.RegisterStartupScript(GetType(), "ex", "alert('" + ex.Message + "');",
true);
}
}

rptVwr.aspx file

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="rptVweTransactionForAccountant.aspx.cs" Inherits="CashFlowMS.Report.rptVweTransactionForAccountant" %>
<%@ Register TagPrefix="CR" Namespace="CrystalDecisions.Web" Assembly="CrystalDecisions.Web, Version=13.0.4000.0, Culture=neutral, PublicKeyToken=692fbea5521e1304" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">

<title></title>

<body>
<form id="form1" runat="server">



<div id="boxes">
<h2>Transactional Reports Generating Page</h2>
<div id="right-box">

<p style="margin-left: 147px">
<asp:DropDownList ID="drpTransactionType" runat="server" AutoPostBack="true" Height="35px" Style="margin-left: 0px" Width="188px"></asp:DropDownList>
<asp:DropDownList ID="drpBank" runat="server" AutoPostBack="true" Height="33px" OnSelectedIndexChanged="drpBank_SelectedIndexChanged" Style="margin-left: 12px" Width="189px"></asp:DropDownList>
<asp:DropDownList ID="drpBranch" runat="server" AutoPostBack="true" Height="33px" Style="margin-left: 11px" Width="193px"></asp:DropDownList>
</p>
<p style="margin-left: 291px">
<asp:Label ID="Label1" runat="server" Text="From:"></asp:Label>
<asp:TextBox ID="txtStartDate" runat="server" TextMode="Date"></asp:TextBox>

<asp:Label ID="Label2" runat="server" Text="To:"></asp:Label>
<asp:TextBox ID="txtEndDate" runat="server" TextMode="Date"></asp:TextBox>

</p>

<asp:Button ID="btnTransactionHistory" runat="server" BackColor="#33CC33" BorderColor="#00CC00" ForeColor="White" Height="31px" OnClick="btnTransactionHistory_Click" OnClientClick="target = '_blank'" Style="margin-left: 184px" Text="Show Transaction History" Width="199px" />
</div>
</div>
<CR:CrystalReportViewer ID="cryslRptVwrTransactionHistoryAccountant" runat="server" AutoDataBind="true" />
</form>
</body>
</html>
web.config file

<?xml version="1.0"?><!--
For more information on how to configure your ASP.NET application, please visit
https://go.microsoft.com/fwlink/?LinkId=301880
--><configuration>
<configSections>
<!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false"/>
</configSections>
<connectionStrings>
<add name="AAAAA" connectionString="Data Source=AAA; Initial Catalog=AAAA; Connect Timeout=60; Integrated Security=SSPI;"
providerName="System.Data.SqlClient" />
<add name="AAA" connectionString="metadata=res://*/AAAA.AAA.csdl|res://*/CashFlowDB.CashFlowDB.ssdl|res://*/AAAAA.msl;provider=System.Data.SqlClient;provider connection string="data source=AAAA;initial catalog=AAA;integrated security=True;MultipleActiveResultSets=True;App=EntityFramework""
providerName="System.Data.EntityClient" />
<add name="AAAA.Properties.Settings.connection" AAAA="Data Source=AAAA; Initial Catalog=AAAA; Connect Timeout=60; Integrated Security=false;User ID=sa;Password=#AAAAAAA" />
</connectionStrings>
<appSettings>
<add key="webpages:Version" value="3.0.0.0" />
<add key="webpages:Enabled" value="false" />
<add key="ClientValidationEnabled" value="true" />
<add key="UnobtrusiveJavaScriptEnabled" value="true" />
<add key="CrystalImageCleaner-AutoStart" value="true" />
<add key="CrystalImageCleaner-Sleep" value="60000" />
<add key="CrystalImageCleaner-Age" value="120000" />
</appSettings>
<system.web>
<authentication mode="None"/>
<compilation debug="true" targetFramework="4.7.2">
<assemblies>
<add assembly="CrystalDecisions.Web, Version=13.0.4000.0, Culture=neutral, PublicKeyToken=692FBEA5521E1304"/>
<add assembly="log4net, Version=2.0.12.0, Culture=neutral, PublicKeyToken=669E0DDF0BB1AA2A"/>
<add assembly="CrystalDecisions.ReportAppServer.Controllers, Version=13.0.4000.0, Culture=neutral, PublicKeyToken=692FBEA5521E1304"/>
<add assembly="CrystalDecisions.ReportAppServer.DataDefModel, Version=13.0.4000.0, Culture=neutral, PublicKeyToken=692FBEA5521E1304"/>
<add assembly="CrystalDecisions.CrystalReports.Engine, Version=13.0.4000.0, Culture=neutral, PublicKeyToken=692fbea5521e1304"/>
<add assembly="CrystalDecisions.ReportSource, Version=13.0.4000.0, Culture=neutral, PublicKeyToken=692fbea5521e1304"/>
<add assembly="CrystalDecisions.Shared, Version=13.0.4000.0, Culture=neutral, PublicKeyToken=692fbea5521e1304"/>
<add assembly="CrystalDecisions.ReportAppServer.ClientDoc, Version=13.0.4000.0, Culture=neutral, PublicKeyToken=692fbea5521e1304"/>
</assemblies>
</compilation>
<httpRuntime targetFramework="4.7.2"/>
<httpHandlers><add verb="GET" path="CrystalImageHandler.aspx" type="CrystalDecisions.Web.CrystalImageHandler, CrystalDecisions.Web, Version=13.0.4000.0, Culture=neutral, PublicKeyToken=692fbea5521e1304"/></httpHandlers></system.web>
<system.webServer>
<modules>
<remove name="FormsAuthentication"/>
</modules>
<handlers>
<add name="CrystalImageHandler.aspx_GET" verb="GET" path="CrystalImageHandler.aspx" type="CrystalDecisions.Web.CrystalImageHandler, CrystalDecisions.Web, Version=13.0.4000.0, Culture=neutral, PublicKeyToken=692fbea5521e1304" preCondition="integratedMode"/>
</handlers><validation validateIntegratedModeConfiguration="false"/></system.webServer>

Accepted Solutions (1)

Accepted Solutions (1)

DonWilliams
Active Contributor
0 Kudos

Hi Assay,

What likely is happening is due to the report going out of scope due to not using PostBack function.

Have a look at this:

https://userapps.support.sap.com/sap/support/knowledge/en/1985571

https://blogs.sap.com/2011/04/25/why-should-i-store-reports-object-in-httpsession/

Don

Answers (0)