Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Shaun E on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

mouse over on image hyperlink opposed to image button

Status
Not open for further replies.

jmeckley

Programmer
Jul 15, 2002
5,269
US
I have a mouse over event that will change the graphic of a button using javascript pretty straight forward. I use the same logic on a hyperlink, but the mouse over event does not seem to change the object. Here's my code
[tt]
'Image Button
ImgBtnChoice.Attributes.Add("onmouseover", "this.src='/GalleryCatalog/Image/arrow_sel.gif';")
ImgBtnChoice.Attributes.Add("onmouseout", "this.src='/GalleryCatalog/Image/arrow_unsel.gif';")
'Hyperlink
lnkAdvanceBid.Attributes.Add("onmouseover", "this.src='/GalleryCatalog/Image/arrow_sel.gif';")
lnkAdvanceBid.Attributes.Add("onmouseout", "this.src='/GalleryCatalog/Image/arrow_unsel.gif';")
[/tt]
If I make the hyperlink button an image button it works fine. Any ideas?

Jason Meckley
Database Analyst
WITF
 
The ImageButton control generates an html <img>, which has the &quot;src&quot; attribute, so you can use it to swap image source. The LinkButton generates an html <a> element, which doesn't have any attributes allowing for background images.
 
but it does allow for images instead of text? Is there no way to use a mouse over on a hyperlink?

Jason Meckley
Database Analyst
WITF
 
You can put logic into the mouseover/mouseout events of a hyprelink for say changing color of the link, or trigger some other kind of logic, but you can't turn an <a> tag into an <img>. You can change a background image of a parent table cell, in which this hyperlink is sitting. But wouldn't the ImageButton control do it?
 
it does, but it causes a post back, would prefer if it didn't. Thanks for the clarification!

Jason Meckley
Database Analyst
WITF
 
You can make an ImageButton not to post back but just redirect to another URL:
Code:
on the page:
<head>
<script language=javascript>
  function doRedirect(){		
    window.location = &quot;[URL unfurl="true"]http://msn.com&quot;;[/URL]			
    return false;
  }
</script>
</head>

code behind:
if(ImageButton1.Attributes[&quot;onclick&quot;] == null)
{
  ImageButton1.Attributes.Add(&quot;onclick&quot;, &quot;javascript:return doRedirect();&quot;);
}
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top