What I posted here would be incorrect.
It would be:
ImageButton1.Attributes.Add("onMouseOver",
this.src='" + HttpContext.Current.Request.ApplicationPath.ToStri ng +
"/Images/hover.gif'");
You are adding Javascript event handlers as attributes to the final img tag
that's being produced in HTML. You want the onmouseover and onmouseout
events to change teh img tags src attribute. I didn't add the
"this.src="[file path]" in my previous post, my appologies.
"William Niver" wrote:
> Try:
>
> ImageButton1.Attributes.Add("onMouseOver",
> HttpContext.Current.Request.ApplicationPath.ToStri ng + "/Images/hover.gif'");
> ImageButton1.Attributes.Add("onMouseOut",
> HttpContext.Current.Request.ApplicationPath.ToStri ng + "/Images/normal.gif'");
>
> "Jeff" wrote:
>
> > hi
> >
> > asp.net 3.5
> >
> > <asp:ImageButton ID="ImageButton1" ImageUrl="~/Images/normal.gif"
> > runat="server" />
> >
> > protected void Page_Load(object sender, EventArgs e)
> > {
> > if (!Page.IsPostBack)
> > {
> > ImageButton1.Attributes.Add("onMouseOver",
> > "ImageUrl='~/Images/hover.gif'");
> > ImageButton1.Attributes.Add("onMouseOut",
> > "ImageUrl='~/Images/normal.gif'");
> > }
> > }
> >
> > when the page loads it displays the ImageButton with the correct image, but
> > when I hover the mouse over the image then I get a broken image icon. when I
> > move the mouse away from the ImageButton I still get the broken image
> > icon...
> >
> > any ideas what I do wrong here?
> >
> >
> >
|