Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

show image

Status
Not open for further replies.

mjd3000

Programmer
Apr 11, 2009
136
GB
I have images in my database that are stored as bytes, and I want to show them on screen on my webpage. I can do this with the code below :

Response.Clear();
Response.ContentType = "image/jpeg";

System.Drawing.Image image = retrieveImage(strEncodedImage);
image.Save(Response.OutputStream, System.Drawing.Imaging.ImageFormat.Jpeg);

But this always clears what is on the rest of the webpage. How can I do this whilst keeping the rest of the page intact?
 
1) Put this code in a seperate aspx file, and have your main page point the images source to the new aspx file, that way the output is written just to the image container on the page.
 
use a generic handler (ashx) to process the image, there is not need for a Page life cycle. then you can point the image in the source as if it was a file.
Code:
<img src="getimagefromdatabase.ashx?id=<%=the id%>" />

Jason Meckley
Programmer
Specialty Bakers, Inc.

faq855-7190
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top