This is a migrated thread and some comments may be shown as answers.

Programatically generate report

2 Answers 168 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Aydın Kara
Top achievements
Rank 1
Aydın Kara asked on 16 Jun 2008, 12:25 PM
Hi,

I want to generate report programatically. I have a button on a web user control. The code of the button click event:

IzinRaporu

rapor = new IzinRaporu(); // my report class

rapor.DataSource =

Servis.izinRaporla(Convert.ToInt32(TextBox1.Text)); // I'm creating a new SqlDataAdaptor

this.rptView.Report = rapor; // rptView is my ReportViewer control

This code works on an aspx page but it doesn't work on a user control. In user control after setting report object to the Report parameter of ReportViewer, contructor of report is called again and datasource of the report becomes null.

Do you have any idea?   

Thanks.

2 Answers, 1 is accepted

Sort by
0
Svetoslav
Telerik team
answered on 17 Jun 2008, 08:45 AM
Hello Hasan ARSLAN,

The code snippet you sent looks fine - the report (IzinRaporu) is created and initialized correctly. If the second time when IzinRaporu is instantiated, its DataSource is not initialized (null), it looks like there is another code that constructs the report for the 2nd time but does not set its data source. In the code snippet below the data source is initialized, so please check that the report is created only once.

In order to help you, we need to examine you web site - the user control with the report viewer and the web page that hosts this control.

Before sending your project there are several things you can check on your side. Please make sure that you handle the button (and all other page/control) events correctly. The best way to find why this code is called twice is to set a break point on the 1st line of the code snippet and explore the call stack. Also make sure that you use the AutoEventWireup attribute correctly. Check this MSDN article out, that describes the ASP.NET server event code model helpful. Also make sure you do not have explicit Page.DataBind() calls in your page that might cause problems.

Sincerely yours,
Svetoslav
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
Aydın Kara
Top achievements
Rank 1
answered on 17 Jun 2008, 10:27 AM
Hi,

Thanks for the response. I solved the problem by using Session. 
I set a session object on button click event and check that session object at Report class by HttpContext.Current.Session.

Thanks..

Tags
General Discussions
Asked by
Aydın Kara
Top achievements
Rank 1
Answers by
Svetoslav
Telerik team
Aydın Kara
Top achievements
Rank 1
Share this question
or