Solved

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

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

Problems using Powershell and Active Directory?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

Question has a verified solution.

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

Suggested Solutions

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…
Sometimes in DotNetNuke module development you want to swap controls within the same module definition.  In doing this DNN (somewhat annoyingly) swaps the Skin and Container definitions to the default admin selections.  To get around this you need t…
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…

832 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