Solved

Trying to add image rollover for LinkButton in ascx table

Posted on 2003-11-18
4
307 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 500 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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Asp.Net Session Question 2 47
orderby list (from Json) 1 42
T-SQL and CLR parameter strings 9 62
XML XDocument extract - Keeping a node list like a menu path 8 33
For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
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…
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …

739 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