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 bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

mouse over event on an image button?

Status
Not open for further replies.

jmeckley

Programmer
Jul 15, 2002
5,269
US
I have an image button and I would like the image to change when I move the mouse over the button. The button is located within a user control (not a webform)
Here is the javascript I have in the user control[tt]
<script language=javascript>
imgBtnSearch = new Image();
imgBtnSearch.src = &quot;\GalleryCatalog\Image\arrow_sel.gif&quot;;
</script>
[/tt]
Note: since this is a user control the script will be written in the body of the text, not the header.
Here is the vbcode to add the javascript attributes.[tt]
imgBtnSearch.Attributes.Add(&quot;onmouseover&quot;, &quot;imgBtnSearch.src='\GalleryCatalog\Image\arrow_sel.gif';&quot;)
imgBtnSearch.Attributes.Add(&quot;onmouseout&quot;, &quot;imgBtnSearch.src='\GalleryCatalog\Image\arrow_unsel.gif';&quot;)
[/tt]
I piece mailed this code together from google and forum searches.

The code doesn't error out, but it also does not execute at all. any ideas? thanks for your help.


Jason Meckley
Database Analyst
WITF
 
finally found the code on gotdotnet[tt]
<asp:ImageButton
id=&quot;imgBtnSearch&quot;
runat=&quot;server&quot;
ImageUrl=&quot;/GalleryCatalog/Image/arrow_unsel.gif&quot;
onmouseover=&quot;this.src='/GalleryCatalog/Image/arrow_sel.gif';&quot;
onmouseout=&quot;this.src='/GalleryCatalog/Image/arrow_unsel.gif';&quot;>
</asp:ImageButton>[/tt]
I think the reason I did not think that would work is because the javascript events are underlined in my ascx file. The tool tip says it does not know what the attribute is.

I'm going to tool around and try to put this in the code behind file.

Jason Meckley
Database Analyst
WITF
 
You can attach a javascript to a control in the code behing, inside the OnInit event:
Code:
override protected void OnInit(EventArgs e)
{
  InitializeComponent();
  base.OnInit(e);

  if(imgBtnSearch.Attributes[ &quot;onmouseover&quot; ] == null)
  {
    imgBtnSearch.Attributes.Add(&quot;onmouseover&quot;, &quot;javascript:this.src='/GalleryCatalog/Image/arrow_sel.gif'&quot;);
  }

  if(imgBtnSearch.Attributes[ &quot;onmouseout&quot; ] == null)
  {
    imgBtnSearch.Attributes.Add(&quot;onmouseout&quot;, &quot;javascript:this.src='/GalleryCatalog/Image/arrow_unsel.gif'&quot;);
  }
}
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top