473,394 Members | 1,828 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

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 2041
<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";
}
</script>

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;
}
}
</script>
Oct 4 '11 #4

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

Similar topics

4
by: crhaynes | last post by:
I'm having trouble with my CSS. My links are black, my hover is orange and my active link is red. When I select a link it turns red but i does not retain that color when the selected page loads. ...
5
by: Ray | last post by:
Hi, I was wondering if anyone has any idea how this can be done. I am trying to show/hide navigation links based on server names or ip addresses. So if, someone visits a particular url/ip address...
31
by: Greg Scharlemann | last post by:
Given some recent success on a simple form validation (mainly due to the kind folks in this forum), I've tried to tackle something a bit more difficult. I'm pulling data down from a database and...
2
by: Stephen Zachmann | last post by:
Ok, I want to have a directory full of pdf files and a page that creates links to them dynamically so that if I add 10 docs or subtract 7 or whatever, they will be added or removed the next time...
3
by: snitu | last post by:
hello I have a problem that how to use different css files in one single page. In that page how to pass link using dropdown menu and select link for css file and it will change the color of whole...
5
by: annaGold | last post by:
Hello, I wrote this simple javascript to demonstrate my problem with IE6 & 7. The code works find in Mozilla, but in IE my email link on the page is changed to the new href. Only href should change,...
2
by: ramaswamynanda | last post by:
Hello All, I am a newbie to web development, so please help me out with this issue. html --------- <form id="Form1" method="post" runat="server"> <asp:TextBox id="txtempid"...
4
by: sgxbytes | last post by:
Hi, My html has <Table style="year-button-archive" width="60%" > <tr> <td class="gold" > <a title="year">By Year:</a> <td class="gold"> <a id = "2008"...
2
by: jkizmannRU09 | last post by:
I know how to adjust the look of visited links with a CSS stylesheet, but how would one create individual variations among a set of links? For example, say I have three links, all initially...
4
pradeepjain
by: pradeepjain | last post by:
i have a menu of 4 items.all text color is white. and when i click a menu link the other menu items text color should change to black! Is it possible to do with css or javascript help is needed for...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.