HTML code blocked by Response.OutputStream.Write

Discussion in 'ASP .Net' started by Richard, Jan 2, 2004.

  1. Richard

    Richard Guest

    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?
    Richard, Jan 2, 2004
    #1
    1. Advertising

  2. 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
    Craig Deelsnyder, Jan 2, 2004
    #2
    1. Advertising

  3. Richard

    Richard Huff Guest

    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!
    Richard Huff, Jan 2, 2004
    #3
  4. 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
    Craig Deelsnyder, Jan 2, 2004
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Ryan Hartman

    large files via Response.OutputStream.Write

    Ryan Hartman, Nov 4, 2003, in forum: ASP .Net
    Replies:
    6
    Views:
    7,284
    Ryan Hartman
    Nov 11, 2003
  2. André
    Replies:
    3
    Views:
    1,880
    André
    Dec 1, 2006
  3. Replies:
    2
    Views:
    3,558
  4. Victor
    Replies:
    3
    Views:
    724
    Victor
    May 9, 2007
  5. Richard
    Replies:
    1
    Views:
    239
    Bob Barrows
    Jan 2, 2004
Loading...

Share This Page