How to mix ContentType in same page?

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()
 
S

Steve C. Orr [MVP, MCSD]

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
 
H

Hans Kesting

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
 
B

bruce barker \(sqlwork.com\)

this can be done with most modern browsers, but not ie (until version 7).

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

-- bruce (sqlwork.com)
 
P

pamelafluente

Thanks Steve.
I downloaded your code. Beautiful !

Ciao,

-P

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

Baski

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

pamelafluente

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()
 
S

Steve C. Orr [MVP, MCSD]

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

Hans Kesting

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
 

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

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,020
Latest member
GenesisGai

Latest Threads

Top