Solved

Trying to add image rollover for LinkButton in ascx table

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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

This article describes relatively difficult and non-obvious issues that are likely to arise when creating COM class in Visual Studio and deploying it by professional MSI-authoring tools. It is assumed that the reader is already familiar with the cla…
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…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

746 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

13 Experts available now in Live!

Get 1:1 Help Now