HTML code blocked by Response.OutputStream.Write

R

Richard

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?
 
C

Craig Deelsnyder

Richard said:
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).
 
R

Richard Huff

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?
 
C

Craig Deelsnyder

Richard said:
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?

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....
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,764
Messages
2,569,567
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top