Reputation: 1171
I have a relatively simple page with an asp:Image tag on it:
<asp:Image id="imgSelect" name="imgSelect" runat="server" src=""/>
I am trying to set a data URI into the image from the code behind.:
data:image/jpeg;base64,...
Nothing I do is getting the image to load on the page. I have tried:
imgSelect.ImageUrl = "data:image/jpeg;base64,...";
imgSelect.DescriptionUrl = "data:image/jpeg;base64,...";
imgSelect.Attributes["src"] = "data:image/jpeg;base64,...";
imgSelect.Attributes.Add("src", "data:image/jpeg;base64,...");
I know my Data URI is good since I have tested it online. I also created a simple JS method that works fine:
function simpleTest() {
var img = document.getElementById("imgSelect");
img.src = "data:image/jpeg;base64,...";
} // simpleTest
Is this not something that can be done with code behind or am I just missing something?
Upvotes: 2
Views: 878
Reputation: 1005
Both ImageUrl
and Attributes["src"]
should be fine. I reproduced your example with a tiny sample image and it works fine:
imgSelect.ImageUrl = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsQAAA7EAZUrDhsAAAASSURBVBhXYwCC/1gwlQUZ/gMA9qoY6CSlL48AAAAASUVORK5CYII=";
The above displays a 5x5 black png.
Upvotes: 2