473,387 Members | 1,585 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

How to add onerror event to image url of hyperlink?

I am using an image in a hyperlink...for this image i refer to a url...
Now my question is, that if this url does not return me a image i want to set a default image from another url...

thanks in advance!!
Feb 14 '11 #1
5 5451
yarbrough40
320 100+
what do you mean by "image in a hyperlink"? a hyperlink is traditionally a <a href> object. These objects do not have image properties (they're just text). Do you mean you have an image object that you want to be able to catch if the image is broken or not?
please explain.
Feb 14 '11 #2
In asp.net a hyperlink does have a imageurl property...google it...let me explain with the sample code....
1st I'll show u how i achieved this thru html anchor tag...
Expand|Select|Wrap|Line Numbers
  1. <a href="page1.aspx"
  2. <img alt="" src="http://content.website.com/Events/59x88/image001.jpg" onerror="this.src='http://content.website.com/events/59x88/NoImage.jpg'" />
  3. </a>
Now i want to do the same thing with a hyperlink..i need a replacement for the onerror method....
Feb 15 '11 #3
yarbrough40
320 100+
ahhhh I see. your problem is that you need to place your image object as a separate control within your hyperlink (<a> object) and not as a property:
Expand|Select|Wrap|Line Numbers
  1.  <a href = "page1.aspx"><img alt="" src='http://content.website.com/Events/59x88/image001.jpg' id="hrefID" onerror="this.src='http://content.website.com/events/59x88/NoImage.jpg';" /></a>
visual studio intellisence is going to tell you that "onerror" is not a valid attribute of "img" but just ignore it - beacuse as we all know.... yes it is.

ROCK!
Feb 15 '11 #4
You still didnt undstnd me properly...i already wrote da same code above...i have already done that...bt now i want to do it in code behind..by making a object of hyperlink and using two images inside that...
Feb 16 '11 #5
yarbrough40
320 100+
I am trying to assist you but it looks as though you are not being clear. Nowhere did you mention anything about doing this in code-behind. Also, the original code you wrote does not work - it is formatted incorrectly which is why I corrected it for you. Your original goal was "..i need a replacement for the onerror method" and that is all you said.

Please describe in better detail what you are trying to do and I would be happy to help. here is an example:
  1. there is a button on a form
  2. client clicks this form which posts back the page
  3. in the button click event I want to instantiate a new hyperlink that appears within a placeholder
  4. if (some variable exists) then change the src property of the hyperlink.
etc...
Feb 16 '11 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: bjarthur | last post by:
i have (see below) what i think is a fairly simple algorithm, but yet it doesn't work. given a directory with consecutively numbered jpeg files (1.jpg, 2.jpg, 3.jpg...), it is designed to count...
0
by: Janus | last post by:
Hello. I need a little help to get this thing finished. Im trying to catch js errors and the event works as expected. However I have created an event from doc.parentWindow but when it fires im...
1
by: Daves | last post by:
my gridview should display a column with an image which also is hyperlinked... No problem with: <asp:HyperLinkField DataNavigateUrlFormatString="~/Groups/Default.aspx?group={0}"...
2
by: samuelberthelot | last post by:
Hi, Hi have a hyperlink column in my datagridview. How can I capture the click event on the hyperlink ? Thank you
2
by: Water Cooler v2 | last post by:
onerror event is tied to: 1. the page 2. one per script tag 3. can have cascades of one per control if 3 is true, what are the controls that implement it? PS: I agree that...
0
by: JR | last post by:
I am opening a html page using showModalDialog. To the page's onError event, i am attaching custom event handler. When ever any exception occures, onError event is firing 2 times. I found the same...
1
by: Jake G | last post by:
I was wondering if anyone could help me with this? I am dynamically loading an image after a user selects an item in a list box. If the image is not available I would like to load a nice error...
2
by: Ross Culver | last post by:
Why is that none of the image components have a target property? I want to use an image instead of text to open a page in the search pane, but I can't access the target property of the button,...
1
mariko
by: mariko | last post by:
In a web page I am currently designing, I have to buttons that are images I designed. They would look great with a white or very light blue border color, but the default color is a hideous dark blue....
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.