Here's the code for an image rollover button control that I made.
--
I hope this helps,
Steve C. Orr, MCSD, MVP
http://Steve.Orr.net
/// <summary>
/// ImageRolloverButton Control
/// </summary>
[DefaultProperty("ImageURL"), ToolboxData(
"<{0}:ImageRolloverButton " +
"runat=server></{0}:ImageRolloverButton>")]
public class ImageRolloverButton :
System.Web.UI.WebControls.ImageButton
{
private string s;
/// <devdoc>
/// <para>Gets or sets the URL reference
/// to the image to display when the mouse
/// is moved over the image.</para>
/// </devdoc>
[Bindable(true), Category("Appearance"),
DefaultValue(""), Editor(typeof(
System.Web.UI.Design.ImageUrlEditor), typeof(
System.Drawing.Design.UITypeEditor))]
public virtual string RolloverImageUrl
{
get
{
string s = (string)ViewState["RolloverImageUrl"];
return((s == null) ? String.Empty : s);
}
set
{
s=value;
ViewState["RolloverImageUrl"] = s;
}
}
public override string ImageUrl
{
get {return(base.ImageUrl);}
set {base.ImageUrl=value;}
}
protected override void OnPreRender(EventArgs e)
{
Attributes.Add("onMouseOver", "this.src=MyImage" +
this.ClientID);
Attributes.Add("onMouseOut", "this.src='" +
base.ImageUrl + "'");
this.Page.RegisterStartupScript("MyImageKey" +
this.ClientID,"<script language=javascript>MyImage"
+ this.ClientID + "='" + s + "'</script>");
base.OnPreRender(e);
}
}
}