Tuesday, September 11, 2007

<asp:ImageButton/> Onmouseover onmouseout in C#

You want to change image on mouseover event and to return back original image when mouse goes out. Very simple solution

.aspx file
<asp:imagebutton id="ibOne" runat="server" imageurl="~/images/1.gif" borderwidth="0"></asp:imagebutton>

.aspx.cs

protected void Page_Load(object sender, EventArgs e)
{
ibOne.Attributes.Add("onmouseover", "this.src='images/3o.gif'");
ibOne.Attributes.Add("onmouseout", "this.src='images/4.gif'");
}


See an example of that on vic.bg rate control

No comments: