ASP.NET ImageButton and OnMouseOver

  • Thread starter Thread starter Jay
  • Start date Start date
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
 
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
 
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
 
Back
Top