473,473 Members | 1,879 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

HTML code blocked by Response.OutputStream.Write

I'm working on a site that creates mailing labels. When a label is
generated, two things happen in the background with the image.

First, it is saved as a smaller low-quality .gif on the server and
then presented as a preview using an img tag (also later used for a
history feature on the site).

Second, when the user clicks on the image, a new window appears with
only the mailing label as a high-quality .png graphic. I don't save
the .png image to conserve hardrive space, so I use
response.outputstream.write to output the image array. I do this
because it is important to have crisp barcodes on the labels.

The problem is that by doing this, the html in the aspx file isn't
sent to the client, just the image. I would like to use
window.print() on the client side. I tried using
Page.RegisterStartUpScript; it runs, but isn't output to the user no
matter if it is ran before or after the OutputStream.

Anyone else seen a similar problem?

Is there a way to display an image that is in server memory to an
image tag?
Nov 18 '05 #1
3 3207
Richard wrote:

Is there a way to display an image that is in server memory to an
image tag?


Yes there is. Set the img src to a aspx page:

<img src="myImageWriter.aspx".../>

myImageWriter.aspx must only output your binary data for the image, by
changing the content-type and then using Response.BinaryWrite to write
the bytes to the response stream. Here's one example, look at
ViewImage.aspx and its code-behind:

http://www.developerfusion.com/show/3933/4/

Sorry, it's actually a halfway-there example, but the only one I could
find. Note you should do a Response.Clear before doing anything else
with the Response object. A Response.Flush and Response.End afterwards
would really make sure no extraneous output (HTML, text, etc.) makes it
along with the binary. And make sure you don't set Response.Buffer =
false (by default it's true).
---
Craig Deelsnyder
Microsoft MVP - ASP.NET
Nov 18 '05 #2
Nice little trick and it works great for my project. Thanks for the
help.

I still curious why the outputstream was overwriting the html. Is it
supposed to this?

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 18 '05 #3
Richard Huff wrote:
Nice little trick and it works great for my project. Thanks for the
help.

I still curious why the outputstream was overwriting the html. Is it
supposed to this?

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!


Um, not sure. Was there a Response.Flush/Response.End somewhere in the
code? The HTML in your page (as you pry see it in your .aspx) isn't
output until after Page_Load (and other page related events) run. Via
the Render event/method (once again assuming the default of .Buffer =
true).

Outputting more than one MIME type in the same stream usually corrupts
the stream (the browser doesn't know what it is, like a corrupted file
in Windows). At least I thought so....

--
Craig Deelsnyder
Microsoft MVP - ASP.NET
Nov 18 '05 #4

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

Similar topics

1
by: Richard | last post by:
I'm working on a site that creates mailing labels. When a label is generated, two things happen in the background with the image. First, it is saved as a smaller low-quality .gif on the server...
6
by: Ryan Hartman | last post by:
I am attempting to use the technique in KB 812406 (http://support.microsoft.com/?kbid=812406) to transfer large files via Response.OutputStream.Write. It works GREAT in in debug mode. But...
3
by: ACaunter | last post by:
Hi all, I was wondering why when i create a text file and download it through my website, the download will include all the html code for the given page at the bottom of the text file. i'm...
5
by: Rob Nelder | last post by:
I’m attempting to stream a PDF to the browser so that the user will get the appearance of just opening the PDF in Explorer. The PDF is being generated by the SQL Server Reporting Services web...
2
by: PrePort | last post by:
The goal here is to return a dynamic image from an HttpHandler that I have written. 2 questions 1. I am reading the images into byte fine and cacheing them fine, but what should I use to deliver...
0
by: Dave | last post by:
Hi, I'm trying to download a pdf from a secure location and writ e the response to the browser as listed below. However, the form that runs this codes appears to postback when I encounter the...
2
by: jayesch | last post by:
Hi All, I have a small program that is trying to POST and XML to an ASP.net aspx web page. I am using WebRequest and WebResponse classes for communication between aspx and client program....
0
by: bmeahan | last post by:
I have a c# web app on .net 1.1 framework. Currently I have a process where I can upload files (.doc, .xls, etc) to a my sql database. When trying to open the files however I'm running into an...
4
by: AAaron123 | last post by:
trying to understand the below shown code. After this is run the browser opens a file-save dialog box for saving the file. I wonder how it knows I want the file saved? But more important, the...
0
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,...
0
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...
0
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,...
1
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
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...

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.