How to mix ContentType in same page?

  • Thread starter Thread starter pamelafluente
  • Start date Start date
P

pamelafluente

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()
 
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
 
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
 
this can be done with most modern browsers, but not ie (until version 7).

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

-- bruce (sqlwork.com)
 
Thanks Steve.
I downloaded your code. Beautiful !

Ciao,

-P

Steve C. Orr [MVP, MCSD] 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.
 
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.


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()
 
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...
 
If I understand it correctly, it's not an error (or shortcoming) on the
Actually most other browsers do support embedded images, just not IE6...

You learn something new every day ...

Hans Kesting
 
Back
Top