Click here to Skip to main content
12,896,806 members (57,095 online)
Click here to Skip to main content
Add your own
alternative version


5 bookmarked
Posted 13 May 2009

Changing currently selected hyperlink's color

, 13 May 2009 CPOL
Rate this:
Please Sign up or sign in to vote.
Changing the currently selected hyperlink's color


Playing with hyperlinks on a master page is not easy. Sometimes, you would like to change the colour of your links (i.e., the current page to have a different colour) using the session object. This tutorial shows you how to do this using C#. So, let's get it on the go.

Using the code

I am using Visual Studio 2008 on my machine. Now this also applies to VWD 2005, 2008 and VS 2005. First, create a new website and delete the default.aspx page created by Visual studio. Now, create a master page.

Add the following hyperlinks to the master page in design view:

  • Link 1
  • Link 2
  • Link 3

Now, we need to add code to our master page so that each time the link is selected, the colour changes. We need to check which link is selected and handle that with some code.

Now, let's look at the C# code:

{lnk1.Style.Add("color", "#009900")}; if(Session["Clicked"]=="link2")
{lnk2.Style.Add("color", "#009900")}; if(Session["Clicked"]=="link3")
{lnk3.Style.Add("color", "#009900")};}

That is it. We can change the colour of the selected hyperlink using the master page. Now on each page, we need to change the Session["Clicked"] in the form_load method, like this:


The above code will change on each page.

Points of interest

You can use C# to do some markup.


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Software Developer Supergroup
South Africa South Africa
No Biography provided

You may also be interested in...

Comments and Discussions

Questiongood one Pin
Emad Al Hawary19-May-14 0:39
memberEmad Al Hawary19-May-14 0:39 
QuestionChanging currently selected hyperlink's color Pin
Shwe Nann Thu7-Aug-12 22:31
memberShwe Nann Thu7-Aug-12 22:31 
Generalsecond hyperlink color Pin
SPdo27-Jul-10 2:39
memberSPdo27-Jul-10 2:39 
General[My vote of 1] Improper use of session. Pin
kanu@adatapost13-May-09 17:16
memberkanu@adatapost13-May-09 17:16 
GeneralRe: [My vote of 1] Improper use of session. Pin
Seabata13-May-09 19:52
memberSeabata13-May-09 19:52 
GeneralRe: [My vote of 1] Improper use of session. Pin
Ronald Bosma13-May-09 21:05
memberRonald Bosma13-May-09 21:05 
GeneralRe: [My vote of 1] Improper use of session. Pin
SmirkinGherkin13-May-09 21:18
memberSmirkinGherkin13-May-09 21:18 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.170424.1 | Last Updated 13 May 2009
Article Copyright 2009 by Seabata
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid