Setting Crystal Report parameters via a form problem

C

Chris

Hi,

I'm new to ASP.Net and Crystal but I've been playing with some samples
and have run into a problem.

If I put all my code into the Page_Init sub of a single form and run
that form, the Crystal report runs fine.

Now i am trying to create another web form where I can input
parameters, hit submit and have those parameters passed to the second
form to diplay the Report. Perhaps I don't understand how to pass them
from a web form. I created a sub routine in my 'Reports' form and
moved my code from the Page_Init sub to this sub. Then I try to call
the sub from my Submit action in my parameter entry form. The code
fails when the sub trys to execute the following:

CrystalReportViewer1.ReportSource = myReport

It fails with 'Object reference not set to an instance of an object'.

Here is the code that works if it is in the Page_Init sub:

Imports CrystalDecisions.CrystalReports.Engine
Imports CrystalDecisions.Shared

Public Class WebForm1
Inherits System.Web.UI.Page
Protected WithEvents CrystalReportViewer1 As
CrystalDecisions.Web.CrystalReportViewer

#Region " Web Form Designer Generated Code "

'This call is required by the Web Form Designer.
<System.Diagnostics.DebuggerStepThrough()> Private Sub
InitializeComponent()

End Sub
Private Sub Page_Init(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Init
Dim myReport As New ReportDocument()
Dim crParameterFieldDefinitions As ParameterFieldDefinitions
Dim crParameterFieldDefinition As ParameterFieldDefinition
Dim crParameterValues As ParameterValues
Dim crParameterDiscreteValue As ParameterDiscreteValue
Dim crParameterFieldValues As ParameterValues

'CODEGEN: This method call is required by the Web Form
Designer
'Do not modify it using the code editor.
InitializeComponent()
myReport.Load("c:\inetpub\wwwroot\web_viewer_basic2\imp.rpt")
crParameterFieldDefinitions =
myReport.DataDefinition.ParameterFields
crParameterFieldDefinition =
crParameterFieldDefinitions.Item("Street Number")
crParameterValues = crParameterFieldDefinition.CurrentValues
crParameterDiscreteValue = New ParameterDiscreteValue()
crParameterDiscreteValue.Value = "*400*" '1st current value
crParameterValues.Add(crParameterDiscreteValue)

**Snip, add more paramters. The values are hardcoded right
now.***

Dim crtableLogoninfos As New TableLogOnInfos()
Dim crtableLogoninfo As New TableLogOnInfo()
Dim crConnectionInfo As New ConnectionInfo()
Dim CrTables As Tables
Dim CrTable As Table
Dim TableCounter

With crConnectionInfo
.ServerName = "DATABASE"
.DatabaseName = "dev"
.UserID = "userid"
.Password = password"
End With

**Snip, Loop through and login to all the tables**

CrystalReportViewer1.ReportSource = myReport
CrystalReportViewer1.DataBind()

End Sub

Can anyone give me some pointers on how to submit the parameters from
another form and pass them through to this form? I also suspect that
my declaration may be in the wrong place in the code.

Thanks,

Chris
 
C

Chris

Actually, I solved the problem myself. First, I just used the
Response.Redirect method and passed the variables to the viewer form.
It worked but I wanted it to open in a new browser window so I used
client-side Javascript to do it.

All I need to do now is figure out why my new window is not taking the
focus.
 
C

Chris

Ok, so I set the new window's focus() with Javascript. The new window
still goes to the back with the parent having focus until the actual
page loads (a crystal report). Then the new page gets the focus. I
realize that the parent is submiting back to itself which is why it is
keeping the focus on submit. Is there any way to have the parent just
lose focus the whole time?

(e-mail address removed) (Chris) wrote in message
**snip**
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top