How to mix ContentType in same page?

Discussion in 'ASP .Net' started by pamelafluente@libero.it, Sep 22, 2006.

  1. Guest

    If I would like to place in a page both text and image,
    is it possible? And, in case, how would I correct the following
    code ?

    'tetx
    Response.ContentType = "text.html"
    Response.Write("Hello hello")

    'image
    Response.ContentType = "image/jpeg"
    Dim b As New Bitmap(200, 200)
    Dim g As Graphics = Graphics.FromImage(b)
    g.FillRectangle(New SolidBrush(Color.Red), 0, 0, 200, 200)
    b.Save(Response.OutputStream, ImageFormat.Jpeg)
    g.Dispose()
    b.Dispose()
    , Sep 22, 2006
    #1
    1. Advertising

  2. The text needs to be output into a regular HTML page.
    That HTML page needs to have a regular image tag, such as <img
    src="MyImage.aspx">

    Then in MyImage.aspx you need to output the image with content type
    image/jpeg as you noted.

    This can only be done with two pages as I've described. One page will not
    work. IE6 does not support doing two content types in a single page.

    Here's more info:
    http://SteveOrr.net/articles/ImproveYourImages.aspx

    --
    I hope this helps,
    Steve C. Orr
    MCSD, MVP, CSM
    http://SteveOrr.net


    <> wrote in message
    news:...
    >
    > If I would like to place in a page both text and image,
    > is it possible? And, in case, how would I correct the following
    > code ?
    >
    > 'tetx
    > Response.ContentType = "text.html"
    > Response.Write("Hello hello")
    >
    > 'image
    > Response.ContentType = "image/jpeg"
    > Dim b As New Bitmap(200, 200)
    > Dim g As Graphics = Graphics.FromImage(b)
    > g.FillRectangle(New SolidBrush(Color.Red), 0, 0, 200, 200)
    > b.Save(Response.OutputStream, ImageFormat.Jpeg)
    > g.Dispose()
    > b.Dispose()
    >
    Steve C. Orr [MVP, MCSD], Sep 22, 2006
    #2
    1. Advertising

  3. Hans Kesting Guest

    > The text needs to be output into a regular HTML page.
    > That HTML page needs to have a regular image tag, such as <img
    > src="MyImage.aspx">
    >
    > Then in MyImage.aspx you need to output the image with content type
    > image/jpeg as you noted.
    >
    > This can only be done with two pages as I've described. One page will not
    > work. IE6 does not support doing two content types in a single page.
    >


    If I understand it correctly, it's not an error (or shortcoming) on the
    part of IE, but a limitation of the HTTP protocol. This means that NO
    browser can handle "double content".

    Hans Kesting
    Hans Kesting, Sep 22, 2006
    #3
  4. this can be done with most modern browsers, but not ie (until version 7).

    <img src="data:image/gif;base64,thisIsbase64ImageContent">

    -- bruce (sqlwork.com)

    <> wrote in message
    news:...
    >
    > If I would like to place in a page both text and image,
    > is it possible? And, in case, how would I correct the following
    > code ?
    >
    > 'tetx
    > Response.ContentType = "text.html"
    > Response.Write("Hello hello")
    >
    > 'image
    > Response.ContentType = "image/jpeg"
    > Dim b As New Bitmap(200, 200)
    > Dim g As Graphics = Graphics.FromImage(b)
    > g.FillRectangle(New SolidBrush(Color.Red), 0, 0, 200, 200)
    > b.Save(Response.OutputStream, ImageFormat.Jpeg)
    > g.Dispose()
    > b.Dispose()
    >
    bruce barker \(sqlwork.com\), Sep 22, 2006
    #4
  5. Guest

    Re: How to mix ContentType in same page?

    Thanks Steve.
    I downloaded your code. Beautiful !

    Ciao,

    -P

    Steve C. Orr [MVP, MCSD] ha scritto:

    > The text needs to be output into a regular HTML page.
    > That HTML page needs to have a regular image tag, such as <img
    > src="MyImage.aspx">
    >
    > Then in MyImage.aspx you need to output the image with content type
    > image/jpeg as you noted.
    >
    > This can only be done with two pages as I've described. One page will not
    > work. IE6 does not support doing two content types in a single page.
    >
    > Here's more info:
    > http://SteveOrr.net/articles/ImproveYourImages.aspx
    >
    > --
    > I hope this helps,
    > Steve C. Orr
    > MCSD, MVP, CSM
    > http://SteveOrr.net
    >
    >
    > <> wrote in message
    > news:...
    > >
    > > If I would like to place in a page both text and image,
    > > is it possible? And, in case, how would I correct the following
    > > code ?
    > >
    > > 'tetx
    > > Response.ContentType = "text.html"
    > > Response.Write("Hello hello")
    > >
    > > 'image
    > > Response.ContentType = "image/jpeg"
    > > Dim b As New Bitmap(200, 200)
    > > Dim g As Graphics = Graphics.FromImage(b)
    > > g.FillRectangle(New SolidBrush(Color.Red), 0, 0, 200, 200)
    > > b.Save(Response.OutputStream, ImageFormat.Jpeg)
    > > g.Dispose()
    > > b.Dispose()
    > >
    , Sep 22, 2006
    #5
  6. Baski Guest

    1. You can create a sample aspx page like below

    <html>
    <body>
    <table>
    <tr>
    <td>
    <asp:Label id=lblHelloWorld runat=server>Hello
    World<asp:label>
    </td>
    </tr>
    <tr>
    <td>
    <img src=GetImage.aspx?ImagID="imageName">
    </td>
    </tr>
    </table>
    </body>
    </html>

    2. write a new page called GetImage.aspx on page load of this page
    if(Request["ImageID"] != null)
    Response.WriteFile("..images/Request["ImageID"] ); //I assume you
    stored all your image in image folder under the root.


    <> wrote in message
    news:...
    >
    > If I would like to place in a page both text and image,
    > is it possible? And, in case, how would I correct the following
    > code ?
    >
    > 'tetx
    > Response.ContentType = "text.html"
    > Response.Write("Hello hello")
    >
    > 'image
    > Response.ContentType = "image/jpeg"
    > Dim b As New Bitmap(200, 200)
    > Dim g As Graphics = Graphics.FromImage(b)
    > g.FillRectangle(New SolidBrush(Color.Red), 0, 0, 200, 200)
    > b.Save(Response.OutputStream, ImageFormat.Jpeg)
    > g.Dispose()
    > b.Dispose()
    >
    Baski, Sep 22, 2006
    #6
  7. Guest

    Re: How to mix ContentType in same page?

    Thank you Baski for the nice and clear example,

    it is very useful to have it.

    -P
    Baski ha scritto:

    > 1. You can create a sample aspx page like below
    >
    > <html>
    > <body>
    > <table>
    > <tr>
    > <td>
    > <asp:Label id=lblHelloWorld runat=server>Hello
    > World<asp:label>
    > </td>
    > </tr>
    > <tr>
    > <td>
    > <img src=GetImage.aspx?ImagID="imageName">
    > </td>
    > </tr>
    > </table>
    > </body>
    > </html>
    >
    > 2. write a new page called GetImage.aspx on page load of this page
    > if(Request["ImageID"] != null)
    > Response.WriteFile("..images/Request["ImageID"] ); //I assume you
    > stored all your image in image folder under the root.
    >
    >
    > <> wrote in message
    > news:...
    > >
    > > If I would like to place in a page both text and image,
    > > is it possible? And, in case, how would I correct the following
    > > code ?
    > >
    > > 'tetx
    > > Response.ContentType = "text.html"
    > > Response.Write("Hello hello")
    > >
    > > 'image
    > > Response.ContentType = "image/jpeg"
    > > Dim b As New Bitmap(200, 200)
    > > Dim g As Graphics = Graphics.FromImage(b)
    > > g.FillRectangle(New SolidBrush(Color.Red), 0, 0, 200, 200)
    > > b.Save(Response.OutputStream, ImageFormat.Jpeg)
    > > g.Dispose()
    > > b.Dispose()
    > >
    , Sep 23, 2006
    #7
  8. > If I understand it correctly, it's not an error (or shortcoming) on the
    > part of IE, but a limitation of the HTTP protocol. This means that NO
    > browser can handle "double content".


    Actually most other browsers do support embedded images, just not IE6...

    --
    I hope this helps,
    Steve C. Orr
    MCSD, MVP, CSM
    http://SteveOrr.net
    Steve C. Orr [MVP, MCSD], Sep 24, 2006
    #8
  9. Hans Kesting Guest

    >> If I understand it correctly, it's not an error (or shortcoming) on the
    >> part of IE, but a limitation of the HTTP protocol. This means that NO
    >> browser can handle "double content".

    >
    > Actually most other browsers do support embedded images, just not IE6...


    You learn something new every day ...

    Hans Kesting
    Hans Kesting, Sep 25, 2006
    #9
    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. MJ
    Replies:
    3
    Views:
    6,485
  2. Sam
    Replies:
    0
    Views:
    443
  3. mark | r
    Replies:
    1
    Views:
    128
    Hannibal
    Oct 7, 2003
  4. KJ
    Replies:
    4
    Views:
    669
  5. Andy
    Replies:
    3
    Views:
    544
    rickman
    Sep 11, 2012
Loading...

Share This Page