mouseovers

P

Peter Morris

Newbie here. Trying to get the imageurl of a link to change on mouseover.
I'm using the following code :

-----------------------------------------------
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
Handles Me.Load

Me.lnk_introduction.Attributes.Add("onmouseover",
"lnk_introduction.imageurl =
'~/Images/Buttons/button_introduction_over.gif'; ")

End Sub
 
K

Ken Cox [Microsoft MVP]

Hi Peter,

You're using server-side syntax for client-side code which doesn't work. For
example, on the client, the "src" points to the image, not "imageurl".
Likewise, the use of "~" is meaningless on the client. Here's an example
that should get you going. Let us know if it helps>

Ken
Microsoft MVP [ASP.NET]


<%@ Page Language="VB" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<script runat="server">

Protected Sub Page_Load(ByVal sender As Object, _
ByVal e As System.EventArgs)
' Me.lnk_introduction.Attributes.Add("onmouseover", _
' "this.src='Images/Buttons/button_introduction_over.gif'; ")
lnk_introduction.Attributes.Add("onmouseover", _
"this.src='http://www.gc.ca/images/francaisbt.gif'")
lnk_introduction.Attributes.Add("onmouseout", _
"this.src='http://www.gc.ca/images/englishbt.gif'")

End Sub
</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Mouseover image and mouseout</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:image id="lnk_introduction" runat="server"
imageurl="http://www.gc.ca/images/englishbt.gif" />
</div>
</form>
</body>
</html>
 
P

Peter Morris

Ken Cox said:
Hi Peter,

You're using server-side syntax for client-side code which doesn't work.
For example, on the client, the "src" points to the image, not "imageurl".
Likewise, the use of "~" is meaningless on the client. Here's an example
that should get you going. Let us know if it helps>

Ken
Microsoft MVP [ASP.NET]


Yes, got it working due to your help. Thanks a lot.
 
P

Przemek Ptasznik

Peter said:
This isn't working. The image does not change. What am I doing wrong?
Just use CSS (background-image property and :hover pseudo-class).
There's no need to engage js there.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,020
Latest member
GenesisGai

Latest Threads

Top