469,325 Members | 1,621 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,325 developers. It's quick & easy.

Changing color of links based on page

5 links are there in menu(master page of c#).Now they all links are in white color. if i click on first link it wil change to red and remaining to blue. when i click it wil redirect to one page. when redirected to that page. all links turns to white color itself. but i wan to show first link in red color itself until i click on the other link. when i click on the second link. it should turn to red. remain links to blue.
Sep 29 '11 #1
3 1847
<a id="link5" href="trans.aspx" onclick="this.style.color = 'Red';">Transactions</a>
I have tried this code. This code is working only when click on trans link. but after loading the trans.aspx page it turns to white itself.
Oct 3 '11 #2
protected void Page_Load(object sender, EventArgs e)
string jv = "<script>changeColor();</script>";
ScriptManager.RegisterClientScriptBlock(this, typeof(Page), "JS", jv,false);

<script type="text/javascript">
function changeColor() {
document.getElementById('link5').style.color = "red";

I have tried this. But it is showing this error.
Microsoft JScript runtime error: Object required.

how to fetch id in page load.
Oct 3 '11 #3
Finally i got answer.
<script type="text/javascript">
window.onload = initall;
var URL = location.href;
function initall() {
switch (true) {
case URL.indexOf("page1.aspx") > -1: document.getElementById('link1').style.color = "red"; break;
case URL.indexOf("page2.aspx") > -1: document.getElementById('link2').style.color = "red"; break;
case URL.indexOf("page3.aspx") > -1: document.getElementById('link3').style.color = "red"; break;
case URL.indexOf("page4.aspx") > -1: document.getElementById('link4').style.color = "red"; break;
case URL.indexOf("page5.aspx") > -1: document.getElementById('link5').style.color = "red"; break;
Oct 4 '11 #4

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

4 posts views Thread by crhaynes | last post: by
31 posts views Thread by Greg Scharlemann | last post: by
2 posts views Thread by Stephen Zachmann | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
reply views Thread by harlem98 | last post: by
reply views Thread by listenups61195 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.