Change Link Color
Hi,
i am using asp.net and C#.
I have 4 links which has a forecolor="red"
Test1
Test2
Test3
Test4
when i click the first link Test1 i want it to change color say to forecolor="green" so that i will know that it is
the active link and then when i click the second link Test2 i want Test2 to become the active link that is
forecolor="green" and Test1 should become the link with the default color that is red.
How should i go about?
I am using a hyperlink control and the code looks like this.
But i have a small problem over here i havent specified the forecolor in the above hyperlink but it displays a
default red color. Why does it do so?Have been trying to get rid of it but no luck.
i have created a style sheet and have the following in it
.urlLink a {
font-family: Verdana, Arial, Helvetica, sans-serif;
font-size: 9px;
color: red;
font-weight: bold;
text-decoration: none;
}
.urlLink a:link {
color: red;
}
.urlLink a:active {
color: green;
}
.urlLink a:visited {
color: red;
}
and then i link the hyperlink to the stylesheet. But it doesnt work. So what is wrong???? Any help appreciated.
Thanx in advance.
He ManPosted Jan 6, 2006, 4:28 AM
Try this
***********Code behind************
private void InitializeComponent()
{
this.LinkButton1.Click += new EventHandler(this.changeColor);
this.LinkButton2.Click += new EventHandler(this.changeColor);
this.LinkButton3.Click += new EventHandler(this.changeColor);
this.LinkButton4.Click += new EventHandler(this.changeColor);
this.Load += new EventHandler(this.Page_Load);
}
private void changeColor(object sender, EventArgs e)
{
LinkButton lnk = new LinkButton();
for(int i=1;i<=4;i++)
{
lnk = (LinkButton)this.FindControl("LinkButton" + i);
if(lnk!=null)
{
lnk.CssClass="green";
}
}
lnk = (LinkButton)sender;
lnk.CssClass="red";
}
***********Code behind************
He ManPosted Jan 6, 2006, 4:14 AM