Click here to Skip to main content
15,890,282 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi all i have a div and inside that div i have some anchor tag for navigation.

code is something like below

HTML
<div id="container">
<a href="1.aspx">1</a>
<a href="2.aspx">2</a>
<a href="3.aspx">3</a>
<a href="4.aspx">4</a>
</div>


some css like this...
CSS
#container 
{
font-family:arial;
font-size:11px;
}
#container  a
{
color : black;
}
#container  a:hover
{
color : red;
}
#container  a:visited
{
color : green;
}



now my color setting for the anchor tag is coming from the database. so i want to apply this on server side inside master page using C#.

what i tried

i gave id to each anchor tag and add style attribute. it works for the first time but after that i have add java script to change color on mouse hover and mouse out so when this code runs the main color of the anchor tag is removed and default body color is applied on each anchor tag.

so main issue is when i click on 1.aspx it works ,color apply based on the master page code but now i am on same page and just hover mouse on 1.aspx and mouse out the defaut color take place. so the style of active link is not there.


can someone please help me ?
Posted
Updated 24-Mar-14 21:25pm
v2
Comments
nandakishoreroyal 25-Mar-14 0:38am    
paste the code behind code, and where you have placed.
ravikhoda 25-Mar-14 1:09am    
something like this

<a href="1.aspx" id="one" runat="server">1
<a href="2.aspx" id="two" runat="server">2
<a href="3.aspx" id="three" runat="server">3
<a href="4.aspx" id="four" runat="server">4

on master page load
i write something like this

one.style.add("color","databaseval");
two.style.add("color","databaseval");
three.style.add("color","databaseval");
four.style.add("color","databaseval");

and
one.attribute.add("onmousehover","this.style.color='databasevalforhover'");
one.attribute.add("onmousehout","this.style.color='databasevalforout'");
nandakishoreroyal 25-Mar-14 3:23am    
spelling mistake in onmouseout

you have written "onmousehout" rename to "onmouseout"
ravikhoda 25-Mar-14 3:27am    
try that but on working. actually it works on mouseover and mouseout but when mouseout happen it becomes permanent black color. it should be color from database value. if i click it again it will take value from database.
nandakishoreroyal 25-Mar-14 3:40am    
dont use css while u r using codebehind to apply styles

1 solution

I think you are misusing a:active property. a:active property will be used when you click on the link. It has no relation to the currently opened page. When you mouse out from the link, then it means that the link is not active at that time.

Definition of :active is:

A link becomes active when you click on it.

In one of your comments, you have mentioned that "because a1 is still active page", which means that you are still on a1.aspx page. But it has nothing to do with :active. The css set in a:active will be applied when you click on the link and do not release the mouse button.

For details, check:

http://www.w3schools.com/cssref/sel_active.asp[^]

So basically what you need is that when you are writing the C# code, set the original value of color in the onmouseout.
 
Share this answer
 
v2

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900