Solved

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

Posted on 2004-08-20
4
383 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

[Webinar] Code, Load, and Grow

Managing multiple websites, servers, applications, and security on a daily basis? Join us for a webinar on May 25th to learn how to simplify administration and management of virtual hosts for IT admins, create a secure environment, and deploy code more effectively and frequently.

Question has a verified solution.

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

In an ASP.NET application, I faced some technical problems. In this article, I list them out and show the solutions that I found.  I hope it will be useful. Problem: After closing a pop-up window, the parent page should be refreshed automaticall…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…
Suggested Courses

751 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