Skip to content

Instantly share code, notes, and snippets.

@rahuldass
Last active August 29, 2015 14:04
Show Gist options
  • Save rahuldass/de73436471297a49d3a9 to your computer and use it in GitHub Desktop.
Save rahuldass/de73436471297a49d3a9 to your computer and use it in GitHub Desktop.
Display Default Image when No Image Found #asp.net #html #image

Display Default Image when No Image Found


Display a default Image in the Image control, when the original image is not available. The same solution can be applied to both ASP.NET Image Controls as well as HTML image controls

For ASP.NET Image Control

<asp:Image ID="imgProd" runat="server"
onerror="this.onload = null; this.src='ImageurlORAnyImageHere.jpg';"/>

For HTML Image

<img id="imgProd1" src="someimage.gif"
onerror="this.onerror=null; this.src='ImageurlORAnyImageHere.jpg';" />
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment