Link to home
Create AccountLog in
Avatar of Torrentes
TorrentesFlag for United States of America

asked on

asp:Hyperlink wiht CSS

Hi,
Im trying to get the Hyperlink to look like the regular links.
By regular I mean to have the little hand when you move the mose over it and to change color after you click on it. But, on IE it does not work. I cant us the NavigateUrl because Im using on the behind code with javascript to sent it with some values to another page.

If you need more info please let me know.
 
<style type="text/css">

A.Link

{ text-decoration: underline }

A.Link:active

{ text-decoration: none }

A.Link:hover

{
 color: blue;
 text-decoration: underline;
}

</style>

<asp:Hyperlink ID="test" runat="server" Text="My Page" CssClass="Link" ></asp:Hyperlink>

Thank you,
Avatar of dctuck
dctuck
Flag of United Kingdom of Great Britain and Northern Ireland image

Best thing to do is probably to create two classes in your stylesheet - one for the HyperLink's normal state and another for mouseover, e.g.:

.OverLink
{
      color:Blue;
      text-decoration:underline;
}
.NormalLink
{
      color:Red;
      text-decoration:none;
}

then use the onmouseover and onmouseout events on the HyperLink control:

<asp:HyperLink CssClass="NormalLink" onmouseover="this.className='OverLink'" onmouseout="this.className="NormalLink" ID="HyperLink1" runat="server">HyperLink</asp:HyperLink>

There may be a cleaner, better way of doing this, but this works...
Your link is not acting correctly because it has no URL or HREF
 
Set the NavigateURL to '#'
 
Set the NavigateURL to '#'
 
The behavior you required in your question is actually the default behavior of a hyper link out of box if there is no style set on it. So just remove your hyper link style and let browser to handle the rest.

1. Don't define "CssClass" for the hyper link control
2. Don't define any style for hyper link tag, such as a.link, a.visited, etc.

Then give it a try to see if the result is what you want.
Avatar of Torrentes

ASKER

guy,

I Set the NavigateURL to '#'. But
On IE once a click the link it does not change color, to show that the link was click on.
Create a style for A.Link:visited
 
Create a style for A.Link:visited
 
For some reason is not working on IE

<style type="text/css">
a.Link:visited
{ color: #000000
}
</style>

<asp:Hyperlink ID="test" runat="server" Text="My Page "  Visible="true" NavigateUrl='#' CssClass="Link"></asp:Hyperlink>
Torrentes, Just an FYI, I am looking into this...
ASKER CERTIFIED SOLUTION
Avatar of sagacitysolutions
sagacitysolutions
Flag of United States of America image

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer
Thank you for taking your time to answer my question.