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

Passing a session variable to a report

6 Answers 445 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Darren
Top achievements
Rank 1
Darren asked on 10 Mar 2010, 05:12 PM
Hi All,

I need to pass a session variable to a report.  If I could access the session variables from the report that would be good too.  Any ideas how to do that?

Thanks,
Darren

6 Answers, 1 is accepted

Sort by
0
Peter
Telerik team
answered on 15 Mar 2010, 09:39 AM
Hi Darren ,

In the following example you can see how to access a session variable and pass it to the report parameter:


report1.ReportParameters("InvoiceID").Value = System.Web.HttpContext.Current.Session("InvoiceID")

Let me know whether the proposed solution helps.

All the best,
Peter
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
Darren
Top achievements
Rank 1
answered on 15 Mar 2010, 04:59 PM
Doesn't seem to work directly in the report.  I guess there's not a way to access the session variables directly from the report?
0
Peter
Telerik team
answered on 18 Mar 2010, 09:26 AM
Hi Darren ,

The following code snipped demonstrates how to access a session variable from a Report.

System.Web.HttpContext.Current.Session["InvoiceID"];

Just have in mind that if you are using a separate class library to create the Report you will have to reference the System.Web.dll assembly.

I have attached a sample project.

Greetings,
Peter
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
Jason
Top achievements
Rank 1
answered on 15 Dec 2010, 11:41 PM

If I have a dataset in session I'm assuming I can do the same thing and use it in my NeedDataSource event.....

Telerik.Reporting.Processing.Table table3 = (Telerik.Reporting.Processing.Table)sender;
            DataSet dataSet3 = new DataSet();
            dataSet3 = (DataSet)System.Web.HttpContext.Current.Session["PreviewInvoice"];
            table3.DataSource = dataSet3;

Assuming there is a valid dataset within my session["PreviewInvoice"] variable, will this work?
0
Bill
Top achievements
Rank 1
answered on 09 Jun 2020, 08:58 PM

I am using vs2019 and telerik reporting trial.  The sample earlier in this thread will not load in vs2019 so I am unable to see how it works or where i put the code.

Can you please send me a sa,ple that will show the vs2019 methods

 

Cheers

0
Todor
Telerik team
answered on 19 Jun 2020, 02:14 PM

Hi Bill,

I tested to open Peter Raykov's attachment from 18 Mar 2010 11:26 AM in VS 2019. The Visual Studio 2019 successfully converted the solution and opened it - see the attached screenshot.

Note that this thread is from 2010 and the sample was created with Telerik Reporting version 4.0.10.312. It is a Web Site project that cannot be automatically upgraded to a newer version. The sample demonstrates an approach that is suitable only for the legacy Web Forms Report Viewer. This viewer is no longer actively developed.

For WebForms projects I strongly recommend using the Html5 Web Forms Report Viewer instead. Here are some useful links that will help you start with it:

Consider also opening a Support ticket where to explain your requirement. We may give further advice on how to achieve it with the newer viewer.

Regards,
Todor
Progress Telerik

Progress is here for your business, like always. Read more about the measures we are taking to ensure business continuity and help fight the COVID-19 pandemic.
Our thoughts here at Progress are with those affected by the outbreak.
Bryan
Top achievements
Rank 1
commented on 18 Jun 2022, 02:25 PM

Access to Session variables seems to be Interrmittent.  What accessing from a Report class, the report constructor seems to be called 3 times.   Two of those times, the session variables are available and the third time, they are not and the Httpcontext.current appears to be null.  Very odd behavior.
Todor
Telerik team
commented on 22 Jun 2022, 08:28 AM

Hi Bryan,

You are right that the report needs to be resolved several times by the Reporting REST Service. The reason for this is explained in the 'operationOrigin' part of the article section How does the REST Service know which report definition to use and what parameter values to apply?

Regarding the HttpContext, it is not always accessible in the Report class, as when the rendering starts it happens in another thread that doesn't have access to the HttpContext.

As a workaround, you may use a Report Parameter or UserIdentity.Current to pass the required information to the report. For details I suggest the following resources:

Tags
General Discussions
Asked by
Darren
Top achievements
Rank 1
Answers by
Peter
Telerik team
Darren
Top achievements
Rank 1
Jason
Top achievements
Rank 1
Bill
Top achievements
Rank 1
Todor
Telerik team
Share this question
or