[Solved] AutoPostBack stops working after placing Crystal Report Viewer on page in ASP.Net

Last Reply on Feb 27, 2017 08:21 AM By bhushan98

Posted on Feb 14, 2017 10:20 PM

vs2010

VB.NET CODING

Sir,

On my page I have a textbox with auto post back which populates a Grid View and on Gridview Selection Some details are  shown everything goses fine but as I place Crystal Report Viewer on the page all autopostback stops and even select of GridView also not work .  It is very strange pl. guide.

Thanks

Posted on Feb 16, 2017 05:04 AM

Sir,

Here is .vb file

Imports System.Data
Imports System.Data.SqlClient
Imports System.Data.Sql
Imports System.Configuration
Imports CrystalDecisions.CrystalReports.Engine

Partial Class Default2
    Inherits System.Web.UI.Page
    Public sqlfile As String
    Dim payslip As New ReportDocument()
    Protected Sub TXTNAME_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles TXTNAME.TextChanged
        sqlfile = "pay" + Mid(cboyear.Text, 3, 2) + cbomonth.Text
        SQLPAY.SelectCommand = "SELECT [NAME], [SECTION], [DESIGNAT], [BASIC], [SPL_PAY], [DA], [HRA], [EMPNO] FROM " & sqlfile & " WHERE ([NAME] LIKE '%' + @NAME + '%')"
        GridView1.Visible = True
    End Sub

    Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
        '       If Not IsPostBack Then
        Dim crystalReport As New ReportDocument()
        crystalReport.Load(Server.MapPath("~/payslip.rpt"))
        Dim dspay As Paydata = GetData("select * from " & sqlfile & " where empno=" & GridView1.SelectedDataKey.Value & "")
        crystalReport.SetDataSource(dspay)
        crpayslip.ReportSource = crpayslip
        'End If\
    End Sub

    Private Function GetData(ByVal query As String) As Paydata
        Dim conString As String = ConfigurationManager.ConnectionStrings("payrollConnectionString").ConnectionString
        Dim cmd As New SqlCommand(query)
        Using con As New SqlConnection(conString)
            Using sda As New SqlDataAdapter()
                cmd.Connection = con

                sda.SelectCommand = cmd
                Using dsCustomers As New Paydata()
                    sda.Fill(dsCustomers, "paysliptable")
                    Return dsCustomers
                End Using
            End Using
        End Using
    End Function

End Class

 

 

 

Here is web.config

<?xml version="1.0"?><!--
  For more information on how to configure your ASP.NET application, please visit
  http://go.microsoft.com/fwlink/?LinkId=169433
  --><configuration>
	<configSections>
		<sectionGroup name="businessObjects">
			<sectionGroup name="crystalReports">
				<section name="rptBuildProvider" type="CrystalDecisions.Shared.RptBuildProviderHandler, CrystalDecisions.Shared, Version=13.0.2000.0, Culture=neutral, PublicKeyToken=692fbea5521e1304, Custom=null"/>
				<section name="crystalReportViewer" type="System.Configuration.NameValueSectionHandler"/>
			</sectionGroup>
		</sectionGroup>
	</configSections>
	<appSettings>
		<add key="CrystalImageCleaner-AutoStart" value="true"/>
		<add key="CrystalImageCleaner-Sleep" value="60000"/>
		<add key="CrystalImageCleaner-Age" value="120000"/>
	</appSettings>
	<connectionStrings>
		<add name="ApplicationServices" connectionString="data source=.\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|\aspnetdb.mdf;User Instance=true" providerName="System.Data.SqlClient"/>
		<add name="ConnectionStringpay" connectionString="Data Source=win7\SQLEXPRESS;Persist Security Info=True;User ID=sa;Password=saadmin" providerName="System.Data.SqlClient"/>
		<add name="payrollConnectionString" connectionString="Data Source=acclap\SQLEXPRESS;Initial Catalog=payroll;Persist Security Info=True;User ID=sa;Password=saadmin" providerName="System.Data.SqlClient"/>
		<add name="accountsConnectionString" connectionString="Data Source=acclap\SQLEXPRESS;Initial Catalog=accounts;User ID=sa;Password=saadmin; MultipleActiveResultSets=true" providerName="System.Data.SqlClient"/>
		<add name="genere" connectionString="Data Source=WIN7\SQLEXPRESS;Initial Catalog=accounts;Integrated Security=True" providerName="System.Data.SqlClient"/>
		<add name="incexpConnectionString" connectionString="ProviderName=Microsoft.Jet.OLEDB.4.0;Data Source=D:\modata\incexp.mdb;Persist Security Info=True;Jet OLEDB:Database Password=seeanu"/>
		<add name="examiner" connectionString="Data Source=acclap\sqlexpress;Initial Catalog=examiner;Persist Security Info=True;User ID=sa;Password=saadmin" providerName="System.Data.SqlClient"/>
	</connectionStrings>
	<system.web>
		<compilation debug="true" strict="false" explicit="true" targetFramework="4.0">
			<assemblies>
				<add assembly="CrystalDecisions.CrystalReports.Engine, Version=13.0.2000.0, Culture=neutral, PublicKeyToken=692fbea5521e1304"/>
				<add assembly="CrystalDecisions.ReportSource, Version=13.0.2000.0, Culture=neutral, PublicKeyToken=692fbea5521e1304"/>
				<add assembly="CrystalDecisions.Shared, Version=13.0.2000.0, Culture=neutral, PublicKeyToken=692fbea5521e1304"/>
				<add assembly="CrystalDecisions.Web, Version=13.0.2000.0, Culture=neutral, PublicKeyToken=692fbea5521e1304"/>
				<add assembly="CrystalDecisions.ReportAppServer.ClientDoc, Version=13.0.2000.0, Culture=neutral, PublicKeyToken=692fbea5521e1304"/>
				<add assembly="System.Design, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A"/>
				<add assembly="System.Web.Extensions.Design, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
				<add assembly="System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
				<add assembly="CrystalDecisions.CrystalReports.Design, Version=13.0.2000.0, Culture=neutral, PublicKeyToken=692FBEA5521E1304"/></assemblies><buildProviders><add extension=".rpt" type="CrystalDecisions.Web.Compilation.RptBuildProvider, CrystalDecisions.Web, Version=13.0.2000.0, Culture=neutral, PublicKeyToken=692fbea5521e1304"/></buildProviders></compilation>
		<authentication mode="Forms">
			<forms loginUrl="~/Account/Login.aspx" timeout="2880"/>
		</authentication>
		<membership>
			<providers>
				<clear/>
				<add name="AspNetSqlMembershipProvider" type="System.Web.Security.SqlMembershipProvider" connectionStringName="ApplicationServices" enablePasswordRetrieval="false" enablePasswordReset="true" requiresQuestionAndAnswer="false" requiresUniqueEmail="false" maxInvalidPasswordAttempts="5" minRequiredPasswordLength="6" minRequiredNonalphanumericCharacters="0" passwordAttemptWindow="10" applicationName="/"/>
			</providers>
		</membership>
		<profile>
			<providers>
				<clear/>
				<add name="AspNetSqlProfileProvider" type="System.Web.Profile.SqlProfileProvider" connectionStringName="ApplicationServices" applicationName="/"/>
			</providers>
		</profile>
		<roleManager enabled="true">
			<providers>
				<clear/>
				<add connectionStringName="ApplicationServices" applicationName="/" name="AspNetSqlRoleProvider" type="System.Web.Security.SqlRoleProvider"/>
				<add applicationName="/" name="AspNetWindowsTokenRoleProvider" type="System.Web.Security.WindowsTokenRoleProvider"/>
			</providers>
		</roleManager>
		<httpHandlers><add verb="GET" path="CrystalImageHandler.aspx" type="CrystalDecisions.Web.CrystalImageHandler, CrystalDecisions.Web, Version=13.0.2000.0, Culture=neutral, PublicKeyToken=692fbea5521e1304"/>
		</httpHandlers>
		<pages controlRenderingCompatibilityVersion="4.0" clientIDMode="AutoID"/></system.web>
	<system.webServer>
		<modules runAllManagedModulesForAllRequests="true">
		</modules>
		<handlers><!-- <add name="CrystalImageHandler.aspx_GET" verb="GET" path="CrystalImageHandler.aspx" type="CrystalDecisions.Web.CrystalImageHandler, CrystalDecisions.Web, Version=13.0.2000.0, Culture=neutral, PublicKeyToken=692fbea5521e1304" preCondition="integratedMode" /> -->
		<add name="CrystalImageHandler.aspx_GET" verb="GET" path="CrystalImageHandler.aspx" type="CrystalDecisions.Web.CrystalImageHandler, CrystalDecisions.Web, Version=13.0.2000.0, Culture=neutral, PublicKeyToken=692fbea5521e1304" preCondition="integratedMode"/></handlers>
		<validation validateIntegratedModeConfiguration="false"/>
		<security>
			<authentication>
				<anonymousAuthentication enabled="true" userName=""/>
			</authentication>
		</security></system.webServer>
	<businessObjects>
		<crystalReports>
			<rptBuildProvider>
				<add embedRptInResource="true"/>
			</rptBuildProvider>
			<crystalReportViewer>
				<add key="ResourceUri" value="/crystalreportviewers13"/>
			</crystalReportViewer>
		</crystalReports>
	</businessObjects>
</configuration>

 


Posted on Feb 16, 2017 05:51 AM Modified on on Feb 17, 2017 05:40 AM

Hi bhushan98,

I have cross check your whole code everything working fine.

 

 


Posted on Feb 27, 2017 08:21 AM

I have found finally that there was a problem in web.config.

there was a line in web.config

    <add key="ResourceUri" value="/crystalreportviewers13"/>

This line creates error .....

If I change this to below line it is giving no error

    <add key="ResourceUri" value="~/crystalreportviewers13"/>

This is surprising.