473,785 Members | 2,165 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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(objec t sender, System.EventArg s e)
{
// Put user code to initialize the page here
try
{
ReportDocument rd = new ReportDocument( );
rd.Load(file);
for (int i = 1; i < Request.QuerySt ring.Count; ++i)
{
//setup report parameter
}
MemoryStream oStream = null; // using System.IO
oStream =(MemoryStream) rd.ExportToStre am

(CrystalDecisio ns.Shared.Expor tFormatType.Por tableDocFormat) ;
Response.Clear( );
Response.Conten tType = "applicatio n/pdf";
Response.Buffer = true;
Response.Binary Write(oStream.T oArray());
}
catch (Exception ex)
{
throw new ApplicationExce ption(ex.Messag e, 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.Binary Write 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 1899
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(objec t sender, System.EventArg s e)
{
// Put user code to initialize the page here
try
{
ReportDocument rd = new ReportDocument( );
rd.Load(file);
for (int i = 1; i < Request.QuerySt ring.Count; ++i)
{
//setup report parameter
}
MemoryStream oStream = null; // using System.IO
oStream =(MemoryStream) rd.ExportToStre am

(CrystalDecisio ns.Shared.Expor tFormatType.Por tableDocFormat) ;
Response.Clear( );
Response.Conten tType = "applicatio n/pdf";
Response.Buffer = true;
Response.Binary Write(oStream.T oArray());
}
catch (Exception ex)
{
throw new ApplicationExce ption(ex.Messag e, 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.Binary Write 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
2211
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
2158
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 before and have no idea how to do it). Now these online forms will be shared by 1200 users. VB and ASP will be used as glueware for the writing/coding. For eg, we will be creating navigation pages in ASP & linking into adobe. Any resource on this...
8
4316
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 button at runtime: //----- Code snippet protected System.Web.UI.WebControls.PlaceHolder ImageHolder; private void Page_Load(object sender, System.EventArgs e)
3
4344
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 clicked opens the second form using the window.open(). On the second form I have a textbox (TextBox1) and a button as well. When the second button is clicked it closes the second window with window.close(). What I need to happen is a refresh to...
4
12420
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 button (which will eventually print form the server) that refreshes the page of course. When the page gets refreshed, none of my rows of the table (except the static header area) remain. I figured it was an .EnableViewState issue so I do a...
4
3119
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 UserControls into the PlaceHolder's child control collection depending upon which of the three radio buttons is selected. Each of the three UserControls have postback events themselves triggered by button clicks. The problem I'm having is keeping track of...
12
3175
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 restarting the application. What I did was to create an AppDomain that loaded the plugins and everything was great, until I tried to pass something else that strings between the domains...
6
25916
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
4095
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 following empty folders: /img/products/ /img/news/ /pdf/
0
9647
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9489
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10356
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10162
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10100
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8988
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7509
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5396
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
3
2893
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.