Replace a broken image with a default image via JavaScript In ASP.NET

At previous Article, I explained How to retrieve BLOB Field from Oracle DB via ASP.Net but I found out when an employee not have image in database the output look like as broken
Therefore, I need to replace any broken image with a default image by following the bit steps below :

In Frontt-code  > Picke <img>  tag

<img id=”EmpImg” 
src=”ShowImage.ashx?Account=<%=Request.QueryString["Account"]%>”
alt=”" width=”100px” height=”100px” style=”float:right”/>

Add onError event with the following details

onError="this.onerror=null;this.src='images/User-Administrator-Blue-icon.png';"

Finally, <img> tag should be look like this

<img id=”EmpImg” 
src=”ShowImage.ashx?Account=<%=Request.QueryString["Account"]%>”
 onError="this.onerror=null;this.src='images/User-Administrator-Blue-icon.png';"
alt=”" width=”100px” height=”100px” style=”float:right”/>

Enjoy 🙂

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s