Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Trying to add image rollover for LinkButton in ascx table

Posted on 2003-11-18
4
Medium Priority
?
317 Views
Last Modified: 2012-05-04
I have a custom control that has a menu with a HyperLink in each cell.  It works great, but I would like to have the image flip on mouse over.  Here is the HTML for one of the cells:

<asp:TableCell HorizontalAlign="Center" ID="cellHome" style="Display:">
     <asp:HyperLink runat="server" NavigateUrl="Home.aspx" ForeColor="#291C52"
       ID="lnkHome"> <img src="Images/home.jpg" border="0"></asp:HyperLink>             </asp:TableCell>

I cannot add an onMouseOver event.  For instance, when the user drags the mouse over this cell in the menu, I would like the image to be home_down.jpg instead.

can someone help?  Thanks so much!

0
Comment
Question by:MrDeveloper
[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
  • 2
4 Comments
 
LVL 28

Expert Comment

by:iboutchkine
ID: 9771630
You can try it with javascript

onmouseover="javascript: this.style.backgroundColor='#FFFFC0';"

I dont know hte syntax to change the picture. Maybe someone will help you here

0
 
LVL 12

Accepted Solution

by:
roverm earned 2000 total points
ID: 9774571
I've build this once for a menucontrol as well.
Add this to your Page_load event, NOT postback:


        Dim strScript As String = "<script language='javascript'>" & vbCrLf
        strScript += "function imagetextchange()" & vbCrLf
        strScript += "{" & vbCrLf
        strScript += "if (imagetextchange.arguments.length==0) {return}" & vbCrLf
        strScript += "var tblrw=imagetextchange.arguments[0];" & vbCrLf
        strScript += "var inout=imagetextchange.arguments[1];" & vbCrLf
        strScript += "var idimg=tblrw.id;" & vbCrLf
        strScript += "var sbar=tblrw.winsbar; " & vbCrLf
        strScript += "if (!sbar) {sbar=''}" & vbCrLf
        strScript += "var scursor='';" & vbCrLf
        strScript += "var imgsrc, txtstyle;" & vbCrLf
        strScript += "if (inout=='over') " & vbCrLf
        strScript += "{ imgsrc=tblrw.imghover;scursor='hand';} else " & vbCrLf
        strScript += "{ imgsrc=tblrw.imgnormal;sbar='';}" & vbCrLf
        strScript += "document.body.style.cursor=scursor;" & vbCrLf
        strScript += "window.status=sbar;" & vbCrLf
        strScript += "if (idimg)" & vbCrLf
        strScript += "{ var plaatje=document.getElementById(idimg);" & vbCrLf
        strScript += "if ((plaatje)&&(imgsrc)) {plaatje.src=imgsrc;} }" & vbCrLf
        strScript += "}" & vbCrLf
        strScript += "</script>" & vbCrLf
        Me.Page.RegisterClientScriptBlock("imagebuttonmenuscript", strScript)

Then build the image tag like this:

<img id='yourpicid' src='yourpictureurl' imgnormal='yourpictureurl' imghover='yourhoverpictureurl' winsbar='statusbartext' onmouseover=javascript:imagetextchange(this,'over');  onmouseout=javascript:imagetextchange(this,'');>

As you can see I've added some custom tags:
imgnormal: the url to the 'normal' picture
imghover: the url to the hover picture
winsbar: the text to appear in the statusbar

I've got also a version in which you can show a text under the image. If you want that, just let me know!

D'Mzz!
RoverM
0
 

Author Comment

by:MrDeveloper
ID: 9779401
Thanks so much for the help roverm!
0
 
LVL 12

Expert Comment

by:roverm
ID: 9779544
Anytime! Thanks for the points!

D'Mzz!
RoverM
0

Featured Post

Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

Question has a verified solution.

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

This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…

688 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