Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Building Controls > Image Rollovers with the Hyperlink Control

Reply
Thread Tools

Image Rollovers with the Hyperlink Control

 
 
Nathan Sokalski
Guest
Posts: n/a
 
      02-18-2006
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

http://www.nathansokalski.com/


 
Reply With Quote
 
 
 
 
Kris
Guest
Posts: n/a
 
      02-18-2006
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

 
Reply With Quote
 
 
 
 
Ken Tucker [MVP]
Guest
Posts: n/a
 
      02-18-2006
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" <> wrote in message
news:uf$...
>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
>
> http://www.nathansokalski.com/
>



 
Reply With Quote
 
Patrick.O.Ige
Guest
Posts: n/a
 
      02-18-2006
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" <> wrote in message
news:uf$...
>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
>
> http://www.nathansokalski.com/
>



 
Reply With Quote
 
Darren Kopp
Guest
Posts: n/a
 
      02-18-2006
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

 
Reply With Quote
 
Nathan Sokalski
Guest
Posts: n/a
 
      02-18-2006
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

http://www.nathansokalski.com/

"Darren Kopp" <> wrote in message
news: 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
>



 
Reply With Quote
 
Nathan Sokalski
Guest
Posts: n/a
 
      02-18-2006
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

http://www.nathansokalski.com/

"Kris" <> wrote in message
news: 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
>



 
Reply With Quote
 
Nathan Sokalski
Guest
Posts: n/a
 
      02-18-2006
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

http://www.nathansokalski.com/

"Patrick.O.Ige" <> wrote in message
news:%...
> 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" <> wrote in message
> news:uf$...
>>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
>>
>> http://www.nathansokalski.com/
>>

>
>



 
Reply With Quote
 
Patrick.O.Ige
Guest
Posts: n/a
 
      02-19-2006
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" <> wrote in message
news:...
> 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
>
> http://www.nathansokalski.com/
>
> "Patrick.O.Ige" <> wrote in message
> news:%...
>> 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" <> wrote in message
>> news:uf$...
>>>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
>>>
>>> http://www.nathansokalski.com/
>>>

>>
>>

>
>



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Image Rollovers or CSS a:hover ? RS HTML 2 01-18-2008 04:22 PM
Image Rollovers with the Hyperlink Control Nathan Sokalski ASP .Net 8 02-19-2006 12:09 PM
Image swapping/Rollovers Jeanne D HTML 6 10-25-2005 01:07 AM
Rollovers over a hotspot image Shahid Juma HTML 0 05-12-2004 05:40 PM
db generated image-based menus with javascript rollovers? Les Caudle ASP .Net 0 04-10-2004 04:33 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57