Before_Print event doesn't fire in ASP.NET

Stimulsoft Reports.NET discussion
gunde99
Posts: 27
Joined: Tue Jul 31, 2012 11:23 am

Before_Print event doesn't fire in ASP.NET

Post by gunde99 »

Hello!

I've made a simple test and changed the title of a chart in Before_Print event in designer. It works when I try the preview. When I call the same mrt-file from my ASP.NET page, the event-code doesn't execute. Is there a setting that needs to be enabled?

Thanks!
Alex K.
Posts: 6488
Joined: Thu Jul 29, 2010 2:37 am

Re: Before_Print event doesn't fire in ASP.NET

Post by Alex K. »

Hello,

Please send us your report with test data for analysis.

Thank you.
gunde99
Posts: 27
Joined: Tue Jul 31, 2012 11:23 am

Re: Before_Print event doesn't fire in ASP.NET

Post by gunde99 »

On all the linecharts, i use BeforePrint to set the position of the constant lines. In Chart5 I added code to change the Title just as a test. This all works when I preview the report but not when I render it from code and export as pdf.

You won't be able to run it without the data but perhaps you see something obvious that I missed.

Thanks!
Attachments
Driftsstatistik.mrt
(2.32 MiB) Downloaded 501 times
HighAley
Posts: 8430
Joined: Wed Jun 08, 2011 7:40 am
Location: Stimulsoft Office

Re: Before_Print event doesn't fire in ASP.NET

Post by HighAley »

Hello.

We've checked your code it's right.
Please, check if the right report template is used.
Please, send us code which you export with.

Thank you.
gunde99
Posts: 27
Joined: Tue Jul 31, 2012 11:23 am

Re: Before_Print event doesn't fire in ASP.NET

Post by gunde99 »

Yes, I'm loading the right template. When debugging I can see the event-script on Chart5.

One more test I've done was to set the title from the code, right before the report has been rendered. This change shows up correctly so it definitely looks like the event is not firing.

Here below is the code. I've tried the same code with another mrt-file, with just a single chart without any datasources, and that works.

Code: Select all

public static void CreateReport(String cstr, String strYear, String kommun, String file, String rootPath, bool showConstantLines, float imageQuality, float imageResolution)
    {
        StiOptions.Engine.HideRenderingProgress = true;
        StiOptions.Engine.AllowInvokeProcessChartEventForTemplateOfChart = true;
        StiOptions.Engine.AllowInteractionInChartWithComponents = true;
        StiOptions.Print.AllowUsePaperSizesFromPrinterSettings = false;

        StiReport stiReport1 = new StiReport();
        stiReport1.Load(rootPath + "\\Document\\Rapporter\\Driftsstatistik.mrt");

        //Hide/Show Text and constantlines
        int count = 1;
        string name = "KommunInfo";
        StiComponent cp = null;
        while ((cp = stiReport1.GetComponentByName(name + count.ToString())) != null)
        {
            cp.Enabled = showConstantLines;
            count++;
        }
        StiComponentsCollection coll = stiReport1.GetComponents();
        foreach (StiComponent sc in coll)
        {
            if (sc is StiChart)
            {
                StiChart chart = (StiChart)sc;
                foreach (StiConstantLines cl in chart.ConstantLines)
                {
                    if (cl.Text.ToLower() == "eget värde")
                        cl.Visible = showConstantLines;
                }
            }
        }


        //Connect to database
        stiReport1.Dictionary.Databases.Clear();
        stiReport1.Dictionary.Databases.Add(new StiSqlDatabase("Koppling", cstr));

        //Init variables
        stiReport1.Dictionary.Variables["Artal"].Value = strYear;
        stiReport1.Dictionary.Variables["Kommun"].Value = kommun;
        stiReport1.Dictionary.Variables["Bild"].ValueObject = new Bitmap(rootPath + "\\Document\\Rapporter\\Brunnslock.png");
        stiReport1.Dictionary.Variables["Logga"].ValueObject = new Bitmap(rootPath + "\\Document\\Rapporter\\Logga2.png");
        stiReport1.Dictionary.Variables["Forord"].Value = ("Stockholm i maj 2012");

        //Pdf Quality
        Stimulsoft.Report.Export.StiPdfExportSettings pdf = new Stimulsoft.Report.Export.StiPdfExportSettings();
        pdf.Compressed = true;
        pdf.ImageCompressionMethod = Stimulsoft.Report.Export.StiPdfImageCompressionMethod.Jpeg;
        pdf.DitheringType = Stimulsoft.Report.Export.StiMonochromeDitheringType.Ordered;
        pdf.ExportRtfTextAsImage = false;
        pdf.GetCertificateFromCryptoUI = false;
        pdf.ImageFormat = Stimulsoft.Report.Export.StiImageFormat.Color;
        pdf.ImageQuality = imageQuality;
        pdf.ImageResolution = imageResolution;

        //Test code
        cp = stiReport1.GetComponentByName("Chart5");
        ((StiChart)cp).Title.Text = "Donald duck";

        stiReport1.CalculationMode = StiCalculationMode.Interpretation;
        stiReport1.Render();

        stiReport1.ExportDocument(StiExportFormat.Pdf, file, pdf);
    }
Alex K.
Posts: 6488
Joined: Thu Jul 29, 2010 2:37 am

Re: Before_Print event doesn't fire in ASP.NET

Post by Alex K. »

Hello,

Can you please send us a sample project with test data which reproduces the issue for analysis.

Thank you.
gunde99
Posts: 27
Joined: Tue Jul 31, 2012 11:23 am

Re: Before_Print event doesn't fire in ASP.NET

Post by gunde99 »

Hello!

I can send you a SQL Server (2008 R2) backup-file of the database with all views and stored procedures. Would you like to test with it? How should I send you such a large file? I don't want to upload it in a public forum.

Meanwhile I'm trying a work-around, by doing the events job in my C# code. How do I populate the datasources with data before rendering?

Code: Select all

StiChart ch = (StiChart)stiReport1.GetComponentByName("Chart5");
        StiDataSource ds1 = stiReport1.Dictionary.DataSources["NaMun101"];
        StiDataSource ds2 = stiReport1.Dictionary.DataSources["NaG101"];
        ds1.Connect(true);
        ds2.Connect(true);
        ch.Title.Text = "Testing";
        ch.Title.Visible = true;
        decimal kv = 0;
        decimal cv = 0;
        decimal.TryParse(ds1.GetData("Value1").ToString(), out kv);
        ds2.First();
        while (!ds2.IsEof)
        {
            decimal.TryParse(ds1.GetData("Value1").ToString(), out cv);
            if (kv <= cv)
            {
                ((Stimulsoft.Report.Chart.StiConstantLines)ch.ConstantLines[0]).AxisValue = ds2.GetData("Label1").ToString();
                break;
            }
            ds2.Next();
        }
Alex K.
Posts: 6488
Joined: Thu Jul 29, 2010 2:37 am

Re: Before_Print event doesn't fire in ASP.NET

Post by Alex K. »

Hello,

Please send your files on support@stimulsoft.com

Thank you.
gunde99
Posts: 27
Joined: Tue Jul 31, 2012 11:23 am

Re: Before_Print event doesn't fire in ASP.NET

Post by gunde99 »

Ok, I will!

Can you help me with my other question? What else must I do to populate a datasource (see code in previous post)?

Thanks
Alex K.
Posts: 6488
Joined: Thu Jul 29, 2010 2:37 am

Re: Before_Print event doesn't fire in ASP.NET

Post by Alex K. »

Hello,

Try to use this code in BeforePrint event instead Rendering.

Thank you.
Post Reply