views:

197

answers:

4

Hi, can someone tell me how to programatically set a:visited and a:hover programatically? I am dynamically building up some hyperlinks server side and want to know how to specify unique css behaviour for each link. Otherwise i would set them all in a stylesheet.

Thanks.

+1  A: 

not sure I understand - wouldnt this work?

Hyperlink1.CssClass = MyAnchorClass;

FiveTools
+1  A: 

If you want to set the style for a single item, you can use the CssClass attribute, then set up the classes in your css.

.linkA:visited {
    color: red;
}
.linkB:visited {
    color: blue;
}

In your codebehind:

LinkOne.CssClass = "linkA";
LinkTwo.CssClass = "linkB";
willoller
+1  A: 

Unless things have changed, you can't specify the a:visited and a:hover within an HTML anchor (a) tag, so in the end you will need CSS somewhere (on the page, in a file) and assign the class to each anchor tag, like what willoller said.

Carl J
A: 

here's how you do it inside code

imageButton.Attributes.Add("onmouseout", "this.src='../../../App_Themes/White/Images/default.png';"); imageButton.Attributes.Add("onmouseover", "this.src='../../../App_Themes/White/Images/default.hover.png';"); imageButton.ImageUrl = "~/App_Themes/White/Images/default.png";

Nick