Solved

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

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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

In this Article, I will provide a few tips in problem and solution manner. Opening an ASPX page in Visual studio 2003 is very slow. To make it fast, please do follow below steps:   Open the Solution/Project. Right click the ASPX file to b…
IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

743 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now