Solved

Trying to add image rollover for LinkButton in ascx table

Posted on 2003-11-18
4
293 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
  • 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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
C# Offline Apllication 5 72
C# Single Form 8 44
VB.NET 2008 (3.5 Framework) Remove all items from List 3 23
C# Gridview 1 34
More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
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…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…

825 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