ASP.NET ImageButton and OnMouseOver

J

Jay

I have an imagebutton like so:

<asp:ImageButton onmouseover="this.src='lc.gif';"
onmouseout="this.src='nc.gif';" id="ImageButton1"
runat="server" ImageUrl="nc.gif"
AlternateText="AGR"></asp:ImageButton>

The ImageButton1_Click event is like so:

Private Sub ImageButton1_Click(ByVal sender As System.Object, ByVal e As
System.Web.UI.ImageClickEventArgs) Handles ImageButton1.Click
ImageButton1.ImageUrl = "dc.gif"
ImageButton1.AlternateText &= " selected"
End Sub


When the mouse is over I need to change the image to lc.gif. When the mouse
is NOT over it should default back to its original image (nc.gif). HOWEVER,
when it is clicked it should go to dc.png. and stay there - no more mouse
over, out, etc. How can this be done.

Thanks a lot.

Jay
 
C

Cor

Hi Jay,
I think on this way,
\\\\\\\\\\\\\
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Me.ImageButton1.Attributes("onmouseover") = "this.src='lc.gif';"
Me.ImageButton1.Attributes("onmouseout") = "this.src='nc.gif';"
End Sub

Private Sub ImageButton1_Click(ByVal sender As Object, ByVal e As
System.Web.UI.ImageClickEventArgs) Handles ImageButton1.Click
Me.ImageButton1.Attributes("onmouseover") = "this.src='dc.gif';"
Me.ImageButton1.Attributes("onmouseout") = "this.src='dc.gif';"
End Sub
////////////
I hope this helps?
Cor
 
A

Alex Papadimoulis

Hi Jay,

You'll have to dynamically add the attributes.
ImageButton1.Attributes.Add("OnMouseOver","this.src='lc.gif';) and what not.
Remove those attributes on the Click event like so:
ImageButton1.Attributes("OnMouseOver") = ""

Alex Papadimoulis
 

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

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top