Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > problem with image swapping on imagebutton

Reply
Thread Tools

problem with image swapping on imagebutton

 
 
Jeff
Guest
Posts: n/a
 
      04-29-2009
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?


 
Reply With Quote
 
 
 
 
William Niver
Guest
Posts: n/a
 
      04-29-2009
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?
>
>
>

 
Reply With Quote
 
 
 
 
William Niver
Guest
Posts: n/a
 
      04-29-2009
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?
> >
> >
> >

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Entire page do postback wehn swapping image, problem Jeff ASP .Net 2 04-19-2009 01:22 PM
Problem swapping image in IE with relative url Hubbers Javascript 0 06-01-2006 12:28 PM
Swapping Image Url Guadala Harry ASP .Net 5 08-13-2004 10:00 AM
SQL image (jpeg) to Image or ImageButton or TableRow etc.. RobertH ASP .Net 3 02-17-2004 02:39 AM
image swapping problem Richard HTML 1 09-06-2003 06:13 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57