473,320 Members | 1,612 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Creating PDFs dynamically forces page reload

Hi all,

Im having difficulty serving synamically generated PDFs to clients via
asp.net. Im using crystal reports to generate them. In my page load I have
the following:

private void Page_Load(object sender, System.EventArgs e)
{
// Put user code to initialize the page here
try
{
ReportDocument rd = new ReportDocument();
rd.Load(file);
for (int i = 1; i < Request.QueryString.Count; ++i)
{
//setup report parameter
}
MemoryStream oStream = null; // using System.IO
oStream =(MemoryStream)rd.ExportToStream

(CrystalDecisions.Shared.ExportFormatType.Portable DocFormat);
Response.Clear();
Response.ContentType = "application/pdf";
Response.Buffer= true;
Response.BinaryWrite(oStream.ToArray());
}
catch (Exception ex)
{
throw new ApplicationException(ex.Message, ex);
}
Response.End();
}

Although this works fine, Page_load gets called twice before the pdf is
served to the client. Any ideas why this is? For a time intesive reoprt its
pretty critical that its only run the once!

Some notes:

If the Response.BinaryWrite call is commented out, page_load is only called
once, however I get a blank page (as expected).

On the other hand, if Response.End is commented out, then the pdf is served
as a download ("do you wish to open or save etc") with the aspx page as the
default filename - saving this as a pdf results in the report. Again,
page_load is only called the once.

Keeping both calls in displays the pdf correctly, but only after the second
call to page_load. There is a screen reload between the two calls though.

Thanks in advance,

Shak
Nov 18 '05 #1
1 1878
when IE it loads an file that requires a viewer object (like pdf) it may
request more than once. Older versions of IE will actually do 3 requests.

when the browser get a pdf response, it knows it must load acrobat reader,
so it checks again with a request to only fetch the mime-type (of course if
your page doesn't check the request header, it send the whole response.)
after validation the mime-type, it loads acrobat, then gives acrobat the url
of the pdf. acrobat then downloads the file and displays. with more recent
versions of IE, an attempt is made to keep the file in the download cache to
not bother with extra downloads, but does not always work out.

-- bruce

"spammy" <me@privacy.net> wrote in message
news:2p************@uni-berlin.de...
Hi all,

Im having difficulty serving synamically generated PDFs to clients via
asp.net. Im using crystal reports to generate them. In my page load I have
the following:

private void Page_Load(object sender, System.EventArgs e)
{
// Put user code to initialize the page here
try
{
ReportDocument rd = new ReportDocument();
rd.Load(file);
for (int i = 1; i < Request.QueryString.Count; ++i)
{
//setup report parameter
}
MemoryStream oStream = null; // using System.IO
oStream =(MemoryStream)rd.ExportToStream

(CrystalDecisions.Shared.ExportFormatType.Portable DocFormat);
Response.Clear();
Response.ContentType = "application/pdf";
Response.Buffer= true;
Response.BinaryWrite(oStream.ToArray());
}
catch (Exception ex)
{
throw new ApplicationException(ex.Message, ex);
}
Response.End();
}

Although this works fine, Page_load gets called twice before the pdf is
served to the client. Any ideas why this is? For a time intesive reoprt its pretty critical that its only run the once!

Some notes:

If the Response.BinaryWrite call is commented out, page_load is only called once, however I get a blank page (as expected).

On the other hand, if Response.End is commented out, then the pdf is served as a download ("do you wish to open or save etc") with the aspx page as the default filename - saving this as a pdf results in the report. Again,
page_load is only called the once.

Keeping both calls in displays the pdf correctly, but only after the second call to page_load. There is a screen reload between the two calls though.

Thanks in advance,

Shak

Nov 18 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Ola Fjelddahl | last post by:
hi. I load a script dynamically and it works * everytime with IE6. * sometimes! with Mozilla1.5 <- makes me curious * never with Opera7.11 all tests on WindowsXP. With "sometimes" I mean
2
by: Pawan | last post by:
Hi Guys, I have this current assignment where I have to develop online forms for local municipal authorities. I have to use adobe acrobat to create online forms from PDFs (which I have never done...
8
by: Donald Xie | last post by:
Hi, I noticed an interesting effect when working with controls that are dynamically loaded. For instance, on a web form with a PlaceHolder control named ImageHolder, I dynamically add an image...
3
by: Steve Wark | last post by:
I have created a ASP.NET application and created two forms within the application (Webform1.aspx & Webform2.aspx). On the first form I have placed a textbox (TextBox1) and a button, which when...
4
by: Grigs | last post by:
Hello, I have an asp:table on my page. I am, after a button gets clicked, programmatically adding rows and their cells. Using the Cell.Text = to put the value in the cell. I then have another...
4
by: Harry | last post by:
Hello, I have a page with a RadioButtonList and a PlaceHolder control. The RadioButtonList's AutoPostBack attribute is set to TRUE and its SelectedIndexChanged event loads one of three...
12
by: Mats Lycken | last post by:
Hi, I'm creating a CMS that I would like to be plug-in based with different plugins handling different kinds of content. What I really want is to be able to load/unload plugins on the fly without...
6
by: Rain | last post by:
Does anyone have an idea on how to programmatically force a page to reload(refresh)? Im developing a asp.net web application using C#.. any help would be nice... Thanks in advance!
7
by: Zeb | last post by:
Hi all I've developed a shopping cart in C# and to allow moderators to upload product images, news images and downloadable PDFs, the app creates a folder for each product. I start out with the...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.