Solved

mouseover event? need to change image for an ImageButton on mouseover

Posted on 2004-08-20
4
382 Views
Last Modified: 2012-06-21
Hi experts --

I need to change my ImageUrl to something else (a different image) when the mouse is placed over an ImageButton.  What is a good way to do this?

Thanks in advance,

Dan
0
Comment
Question by:djhoen
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
4 Comments
 
LVL 17

Expert Comment

by:AerosSaga
ID: 11856985
I believe using a css class is your best solution

Regards,

Aeros
0
 
LVL 10

Accepted Solution

by:
jnhorst earned 125 total points
ID: 11857454
Dan:

This may point you in the right direction:  I used a couple jpg files from the My Pictures/Sample Picture folder on my XP Pro box.  I put them in an Images folder on my test web application.  You can adjust the script below to follow your desires as for relative paths.  

Add the following within the <HEAD></HEAD> section of the HTML of your aspx page.  

<script language=javascript>
function changeImage(imgCtl, newImgPath)
{
                // this'll work in IE, but probably not well cross browser.
      var ctl = document.getElementById(imgCtl);
      ctl.src = newImgPath;
}
</script>

Then in Page_Load if Page.PostBack == false, add the following: (Image1 is the image control).

this.Image1.Attributes.Add("onmouseover", "javascript:changeImage('" + this.Image1.ID + "', 'Images/Sunset.jpg');");

John


0
 
LVL 8

Expert Comment

by:shovavnik
ID: 11859864
jnhorst's solution is the right way to go.

Just so you understand his solution, keep in mind that asp.net does not throw events for mouse movement.  It would simply generate too many events on the server, and it would be very difficult to actually make use of the data.

Plus, the changing image is a totally client-side, presentation layer type of action.  Avoid sending the data to the server as much as possible.

So really the only reasonable way to do what you want is to make the change on the client, using javascript, as jnhorst demonstrated.
0
 
LVL 1

Author Comment

by:djhoen
ID: 11904065
Thanks a lot guys
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
I have developed many web applications with asp & asp.net and to add and use a dropdownlist was always a very simple task, but with the new asp.net, setting the value is a bit tricky and its not similar to the old traditional method. So in this a…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question