473,396 Members | 2,129 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Image Rollovers with the Hyperlink Control

I have several System.Web.UI.WebControls.HyperLink Controls which I want to
display as rollover images. I know how to make these manually using the <a>
and <img> tags or the <a> tag and a System.Web.UI.WebControls.Image Control
or a HyperLink and Image Controls, but the onMouseOver and onMouseOut
attributes must be in the <img> tag. If I were to use the HyperLink's
ImageUrl property and add the attributes using the
HyperLink.Attributes.Add() method, I am assuming the attributes will appear
in the generated <a> tag. Is there a way to create a Hyperlink Rollover
without creating two Controls? Thanks.
--
Nathan Sokalski
nj********@hotmail.com
http://www.nathansokalski.com/
Feb 18 '06 #1
8 1452
Hi Nathan,

Yes. You need not create two controls.

In HyperLink you have a property called ImageUrl. Use this property to
assign the image location.

Cheers,
Kris

Feb 18 '06 #2
Hi,

I usually use the 2 controls. I try and make the image have a
transparent background. That way when the mouse passes over the hyperlink
the color changes and I dont have to change the image.

The new asp.net 2.0 menu control does a lot of what you are looking
for but I dont know if it work in your application.

Ken
-----------------

Ken
-----------------------
"Nathan Sokalski" <nj********@hotmail.com> wrote in message
news:uf**************@TK2MSFTNGP09.phx.gbl...
I have several System.Web.UI.WebControls.HyperLink Controls which I want to
display as rollover images. I know how to make these manually using the <a>
and <img> tags or the <a> tag and a System.Web.UI.WebControls.Image Control
or a HyperLink and Image Controls, but the onMouseOver and onMouseOut
attributes must be in the <img> tag. If I were to use the HyperLink's
ImageUrl property and add the attributes using the
HyperLink.Attributes.Add() method, I am assuming the attributes will appear
in the generated <a> tag. Is there a way to create a Hyperlink Rollover
without creating two Controls? Thanks.
--
Nathan Sokalski
nj********@hotmail.com
http://www.nathansokalski.com/

Feb 18 '06 #3
Nathan i remember i posted something similar too as i had to fix it up for a
client and you made some sugesstions.
What i did was supposeing you have an hyperlink and and image control like
below in a repaeater etc..

<asp:Image id="Image1" runat="server" name="Image1"
ImageUrl="images/off.gif"></asp:Image>
<asp:HyperLink Tooltip='<%#
DataBinder.Eval(Container.DataItem, "sample") %>'
Cssclass="txtmenu" id="HyperLink1" runat="server" />

You can add the image on mouseover by adding this in your ItemDataBound like
below

If e.Item.ItemType = ListItemType.Item OrElse e.Item.ItemType =
ListItemType.AlternatingItem Then
Dim hyperLink As HyperLink =
CType(e.Item.FindControl("HyperLink1"), HyperLink)
Dim Image As System.Web.UI.WebControls.Image =
CType(e.Item.FindControl("Image1"), System.Web.UI.WebControls.Image)

hyperLink.Attributes.Add("onMouseOver", Image.ClientID &
".src='images/on.gif;return true;")
hyperLink.Attributes.Add("onMouseOut", Image.ClientID &
".src='images/off.gif'; return true;")

End If

And that did the trick..
Hope that helps
** If you need more info let me know.
Patrick

"Nathan Sokalski" <nj********@hotmail.com> wrote in message
news:uf**************@TK2MSFTNGP09.phx.gbl...
I have several System.Web.UI.WebControls.HyperLink Controls which I want to
display as rollover images. I know how to make these manually using the <a>
and <img> tags or the <a> tag and a System.Web.UI.WebControls.Image Control
or a HyperLink and Image Controls, but the onMouseOver and onMouseOut
attributes must be in the <img> tag. If I were to use the HyperLink's
ImageUrl property and add the attributes using the
HyperLink.Attributes.Add() method, I am assuming the attributes will appear
in the generated <a> tag. Is there a way to create a Hyperlink Rollover
without creating two Controls? Thanks.
--
Nathan Sokalski
nj********@hotmail.com
http://www.nathansokalski.com/

Feb 18 '06 #4
Ever thought about making a custom control? I know I made one to make
a link button with an image, inheriting from the link button class. It
wouldn't be too hard to do that with the hyperlink class and just have
properties linkimage and hoverimage. then you create a javascript to
swap the images. In your control you could then check if the script
has been registered, if not register it with the page. This way you
can use the same script with as many controls as you want.

This can help encapsulate your code a little better and maybe make your
life a bit easier :)

HTH,
Darren Kopp
http://blog.secudocs.com

Feb 18 '06 #5
I have thought about that, and someday I probably will, but right now I do
not have enough experience with making custom controls Design View friendly
that I want to do that with this. I have written custom controls in the
past, but am still studying and learning how to make their properties
visible in the places I want (such as the properties palette). Almost
everything I know about ASP.NET has been either self-taught from
books/websites or learned from people in newsgroups, none of the
universities I have attended seem to be big on .NET (if at all) yet.
--
Nathan Sokalski
nj********@hotmail.com
http://www.nathansokalski.com/

"Darren Kopp" <da********@gmail.com> wrote in message
news:11*********************@o13g2000cwo.googlegro ups.com...
Ever thought about making a custom control? I know I made one to make
a link button with an image, inheriting from the link button class. It
wouldn't be too hard to do that with the hyperlink class and just have
properties linkimage and hoverimage. then you create a javascript to
swap the images. In your control you could then check if the script
has been registered, if not register it with the page. This way you
can use the same script with as many controls as you want.

This can help encapsulate your code a little better and maybe make your
life a bit easier :)

HTH,
Darren Kopp
http://blog.secudocs.com

Feb 18 '06 #6
You seem to have misunderstood my problem. I know how to assign an image to
a HyperLink, but I need to make that image a rollover, and I want to use
only one Control.
--
Nathan Sokalski
nj********@hotmail.com
http://www.nathansokalski.com/

"Kris" <kr***********@gmail.com> wrote in message
news:11**********************@z14g2000cwz.googlegr oups.com...
Hi Nathan,

Yes. You need not create two controls.

In HyperLink you have a property called ImageUrl. Use this property to
assign the image location.

Cheers,
Kris

Feb 18 '06 #7
The code you give adds the onMouseOver and onMouseOut to the <a> tag, not
the <img> tag. Because of this, the rollover does not work.
--
Nathan Sokalski
nj********@hotmail.com
http://www.nathansokalski.com/

"Patrick.O.Ige" <na********@hotmail.com> wrote in message
news:%2****************@TK2MSFTNGP14.phx.gbl...
Nathan i remember i posted something similar too as i had to fix it up for
a client and you made some sugesstions.
What i did was supposeing you have an hyperlink and and image control
like below in a repaeater etc..

<asp:Image id="Image1" runat="server" name="Image1"
ImageUrl="images/off.gif"></asp:Image>
<asp:HyperLink Tooltip='<%#
DataBinder.Eval(Container.DataItem, "sample") %>'
Cssclass="txtmenu" id="HyperLink1" runat="server" />

You can add the image on mouseover by adding this in your ItemDataBound
like below

If e.Item.ItemType = ListItemType.Item OrElse e.Item.ItemType =
ListItemType.AlternatingItem Then
Dim hyperLink As HyperLink =
CType(e.Item.FindControl("HyperLink1"), HyperLink)
Dim Image As System.Web.UI.WebControls.Image =
CType(e.Item.FindControl("Image1"), System.Web.UI.WebControls.Image)

hyperLink.Attributes.Add("onMouseOver", Image.ClientID &
".src='images/on.gif;return true;")
hyperLink.Attributes.Add("onMouseOut", Image.ClientID &
".src='images/off.gif'; return true;")

End If

And that did the trick..
Hope that helps
** If you need more info let me know.
Patrick

"Nathan Sokalski" <nj********@hotmail.com> wrote in message
news:uf**************@TK2MSFTNGP09.phx.gbl...
I have several System.Web.UI.WebControls.HyperLink Controls which I want
to display as rollover images. I know how to make these manually using the
<a> and <img> tags or the <a> tag and a System.Web.UI.WebControls.Image
Control or a HyperLink and Image Controls, but the onMouseOver and
onMouseOut attributes must be in the <img> tag. If I were to use the
HyperLink's ImageUrl property and add the attributes using the
HyperLink.Attributes.Add() method, I am assuming the attributes will
appear in the generated <a> tag. Is there a way to create a Hyperlink
Rollover without creating two Controls? Thanks.
--
Nathan Sokalski
nj********@hotmail.com
http://www.nathansokalski.com/


Feb 18 '06 #8
Nathan if you are interested in the img
Try loooking at :-
http://aspnet.4guysfromrolla.com/articles/091703-1.aspx
or
http://aspalliance.com/317
Hope that helps
Patrick
"Nathan Sokalski" <nj********@hotmail.com> wrote in message
news:Oi**************@TK2MSFTNGP10.phx.gbl...
The code you give adds the onMouseOver and onMouseOut to the <a> tag, not
the <img> tag. Because of this, the rollover does not work.
--
Nathan Sokalski
nj********@hotmail.com
http://www.nathansokalski.com/

"Patrick.O.Ige" <na********@hotmail.com> wrote in message
news:%2****************@TK2MSFTNGP14.phx.gbl...
Nathan i remember i posted something similar too as i had to fix it up
for a client and you made some sugesstions.
What i did was supposeing you have an hyperlink and and image control
like below in a repaeater etc..

<asp:Image id="Image1" runat="server" name="Image1"
ImageUrl="images/off.gif"></asp:Image>
<asp:HyperLink Tooltip='<%#
DataBinder.Eval(Container.DataItem, "sample") %>'
Cssclass="txtmenu" id="HyperLink1" runat="server" />

You can add the image on mouseover by adding this in your ItemDataBound
like below

If e.Item.ItemType = ListItemType.Item OrElse e.Item.ItemType =
ListItemType.AlternatingItem Then
Dim hyperLink As HyperLink =
CType(e.Item.FindControl("HyperLink1"), HyperLink)
Dim Image As System.Web.UI.WebControls.Image =
CType(e.Item.FindControl("Image1"), System.Web.UI.WebControls.Image)

hyperLink.Attributes.Add("onMouseOver", Image.ClientID &
".src='images/on.gif;return true;")
hyperLink.Attributes.Add("onMouseOut", Image.ClientID &
".src='images/off.gif'; return true;")

End If

And that did the trick..
Hope that helps
** If you need more info let me know.
Patrick

"Nathan Sokalski" <nj********@hotmail.com> wrote in message
news:uf**************@TK2MSFTNGP09.phx.gbl...
I have several System.Web.UI.WebControls.HyperLink Controls which I want
to display as rollover images. I know how to make these manually using
the <a> and <img> tags or the <a> tag and a
System.Web.UI.WebControls.Image Control or a HyperLink and Image
Controls, but the onMouseOver and onMouseOut attributes must be in the
<img> tag. If I were to use the HyperLink's ImageUrl property and add the
attributes using the HyperLink.Attributes.Add() method, I am assuming the
attributes will appear in the generated <a> tag. Is there a way to create
a Hyperlink Rollover without creating two Controls? Thanks.
--
Nathan Sokalski
nj********@hotmail.com
http://www.nathansokalski.com/



Feb 19 '06 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Neil Woodvine | last post by:
***Scenario ... I have a DataList with a hyperlink WebControl in the Item Template. I want to display a 64x64 image in the Hyperlink and set the NavigateURL to the full size image. ***Source...
2
by: Cynthia | last post by:
I'm looking for javascript code that when I mouse over a menu item will display a picture elsewhere on the page. I know it exists, but the ones I've found so far just swap out the menu item in...
5
by: jedbob | last post by:
I used Adobe Imageready to build a simple rollover navigation bar, where the text will change color on a mouse over. The working example can be found at:...
4
by: Shumit Rehman | last post by:
Hi I have a table which has path names to photos I would like to view. I would like to open some/any kind of image viewer(Paint) to see the picture when I click the pathname. The pictures are...
3
by: Fred R | last post by:
I'm designing an app in Access 97 that will facilitate the uploading of records and images to a website. The user selects the image thumbnails from the file system and drags them into the app....
2
by: Robson Carvalho Machado | last post by:
Dear friends, I'm dynamically creating a Hyperlink with spacer.gif as ImageURL that is an 1px transparent image only to determine link position, but as I create this link dynamically I could not...
8
by: Nathan Sokalski | last post by:
I have several System.Web.UI.WebControls.HyperLink Controls which I want to display as rollover images. I know how to make these manually using the <a> and <img> tags or the <a> tag and a...
1
by: Daves | last post by:
my gridview should display a column with an image which also is hyperlinked... No problem with: <asp:HyperLinkField DataNavigateUrlFormatString="~/Groups/Default.aspx?group={0}"...
3
by: Nathan Sokalski | last post by:
I am using the ImageUrl property of the HyperLink control. My image is large, so I am setting the width/height attributes, but when it renders the width/height attributes are in the <atag rather...
2
by: Casimir | last post by:
I am looking into making pure CSS image rollovers. Do you have any clever (and robust) CSS rollover-tricks? Or links to such "in the wild"? I have figured out two methods for this, but have...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.