0

I know it is be possible to do this:

<asp:Image runat="server" ImageUrl="~/MyImageHandler.ashx?imageid=2" />

...but I have a case where the byte array data is only available to the Page (ie, not available in the session, and cannot be referenced by an id) so I can't point the ImageUrl to a different page.

Is there a way of giving an asp:Image the byte array to render as an Image?

2
  • Where is the byte array coming from? Commented Oct 16, 2009 at 12:37
  • I have update my answer.. check now Commented Oct 16, 2009 at 13:03

2 Answers 2

2

The major hurtle you're going to have to deal with is that an <asp:Image/> element gets rendered as a regular <img />, which needs a src attribute that points at a URL.

That being the case, I see two hairy alternatives:

  • Use the technique described here to embed your image encoded in Base64 in the src attribute. Note that this does not work with Internet Explorer.

  • Embed your Base64-encoded image into the page as a hidden <input /> element. You could then use JavaScript to POST that data back to the server, which would just send it back to the browser using Response.Write() (being sure to set the Content-Type appropriately, of course).

Sign up to request clarification or add additional context in comments.

3 Comments

Yes, I had considered the second option there but had to throw it away as it made me feel a little queasy throwing the data back and forth in that way. Good idea though!
If you're thinking about the second option, you might as well use Session instead (like my answer).
Storing the image in the Session is clearly the better alternative (see also: a database). But if, for whatever reason, you don't have access to either of those (and the filesystem...) then this is really your only option.
1

The only decent solution to this is to put the byte array in session. If you're concerned about uniqueness (multiple people getting each other's byte arrays), use a random GUID as the key.

1 Comment

I'm going to have to give the green tick to this one, just because it would achieve the result, still not in the way I would want it to though - but I'm going to have to conceed that there is no answer to this one

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.