Advertisement

05.08.2008 at 03:06PM PDT, ID: 23387856
[x]
Attachment Details

How to alter css class of an item in asp.net master page at run time?

Asked by fizzer666 in Programming for ASP.NET, JavaScript

Tags: asp.net

I have the following HTML in my ASP.net master page:

 <div id="nav">
                <ul class="glossymenu">
                  <li class="current"><a href=""><b>Home</b></a></li>
                  <li><a href=""><b>About Us</b></a></li>
                  <li><a href=""><b>Case Studies</b></a></li>      
                  <li><a href=""><b>Contact</b></a></li>      
                
                 </ul>
            </div>

Its a css menu that I found on dynamicdrive.com.  The css for this works great and produces a nice tabbed menu bar.  the "current" class highlights the current page tab.  However, because this is in the master page how would I change, for example the "About Us" listItem to have the "Current" style applied.

I dont have much experience with javascript so I tried this in my AboutUs.aspx page:

<script language="javascript" type="text/javascript">
function reWriteMenu(){
   var myMenu =  document.getElementById("nav");
  myMenu.innerHTML = "<ul class='glossymenu'><li><a href=''><b>Home</b></a></li><li class='current'><a href='about.aspx'><b>About Us</b></a></li><li><a href=''><b>Case Studies</b></a></li><li><a href=''><b>Contact</b></a></li></ul>";
                
}
reWriteMenu();
</script>

This worked but it really defeats the object of putting it in the master page because i'd have to change it in every page if the menu changed.  (i'd be re-writting the HTML on every page)  Anyone got any suggestions??Start Free Trial
[+][-]05.08.2008 at 03:49PM PDT, ID: 21529100

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zones: Programming for ASP.NET, JavaScript
Tags: asp.net
Sign Up Now!
Solution Provided By: steveberzins
Participating Experts: 2
Solution Grade: A
 
 
[+][-]05.09.2008 at 01:03PM PDT, ID: 21536025

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32 / EE_QW_2_20070628