Hyperlink's, ImageURL's, and OnError's

I created an ASP:Hyperlink and set the ImageURL attribute so the link will be the image.
If the image is missing, I would like it to display a 'missing image' pic that I have.  I know you can use the OnError attribute of the <img> tag to run some javascript to change it.
Unfortunately I can't find a way to access the Hyperlink's Image that is inside it, so I can add an Attribute so the resulting <img> tag will have an OnError attribute inside of it.

Any help?

If my Hyperlink is called 'foo'....would I do...  ((Image) foo.Controls[0]).Attributes.Add("OnError", "myjavascripthandler();");

How do I get to the Image inside the hyperlink?
 

0
puffpio
10/24/2007 5:43:42 PM
📁 asp.net.getting-started
📃 91979 articles.
⭐ 4 followers.

💬 3 Replies
👁️‍🗨️ 1909 Views

um, ive never really done that, but i would try running the page, viewing the source, and seeing if it gives the image an id, then use find by id. if it doesnt work in the code behind, you can do it with javascript get element by id. if that doesnt work, and youre positive the image is a sub control of the hyperlink control, you could do a

 

for each c as control in foo.controls



if typeof(c) is getType(image)

 add attribute

etcetc 


EXPERT .NET DEVELOPER
0
mod84
10/24/2007 5:57:32 PM

ok i just tested, it doesnt give the image an id... wonderign if you can use an asp:image tag within the hyperlink? or is that not an option

 

mod 


EXPERT .NET DEVELOPER
0
mod84
10/24/2007 6:00:09 PM

Yeah i fixed it on my own.

Instead of using the Hyperlink's ImageURL attribute, I just made an Image inside of it so I had direct access to it programmatically.  Then I added the OnError attribute, hooked up the javascript and I was good to go :) 

0
puffpio
10/24/2007 6:34:23 PM
Reply: