faesel

faesel

  • NA
  • 4
  • 0

Retrieve image from DB and displaying along with components.

Nov 22 2007 10:29 AM
Hi everyone,

Currently i have a aspx page called game.aspx, which contains various components and a button called 'show image' when i press this button i want the image to be retrieved from the sql database and show on game.aspx

At the moment I am using Response.BinaryWrite to display the image to a aspx page called image.aspx, code shown below:

namespace WebApplication.MemberPages
{
    public partial class Image : System.Web.UI.Page
    {
         protected void Page_Load(object sender, EventArgs e)
         {
          }
      
       public void GenerateImage()
        {
            Byte[] content = game.RetrieveImageBinary();  //Gets binary data from the database
            System.Web.HttpContext.Current.Response.BinaryWrite(content);
            System.Web.HttpContext.Current.Response.ContentType = "image/jpg";
        }
     }

In game.aspx i have a imagebox where the source is 'image.aspx'
Code: <asp:Image ID="Image2" runat="server" ImageUrl="Image.aspx"  />

This displays the image correctly, although when doing so all other components that where on the game.aspx page have all disappeared!!

My question is am i doing anything wrong? Is Response.BinaryWrite the best solution to the problem? (i  am willing to take different approaches).
Due to the program being a web application I don’t have access to a picturebox(would have made life a lot easier) and i am not to keen on making a temporary file.

Thanks

Faesel Saeed

Answers (1)