0

In my case, I have an HTML/CSS Menu in the site master.

enter image description here

So, when you hover your mouse over "Graphics", it highlights it (using CSS onHover).

Now what I need to do is that when you actually click on "Graphics" (and it takes you to the graphics page), it remains highlighted, if possible in a different colour.

I'm thinking of modifying the Site.Master style from C# or VB code.

Any ideas? Thanks.

1
  • Does HTML/CSS Menu mean not a server side control? Commented Mar 20, 2012 at 18:09

3 Answers 3

2

An idea would be to check what page you are in, and apply a css class:

    <li class="<%= this.Page.ToString().ToLower().EndsWith("graphics_aspx") ? "selected" : "normal"%>">
Graphics<li>

Hope it helps!

Sign up to request clarification or add additional context in comments.

7 Comments

awesome! I'll try it out and mark this as answer if I manage.
@Reinaldo Hmm, could you look at this screenshot?: gyazo.com/b13a69ae943f1fb096b2dd2e6b4cdb2b It didn't work (as I did it). My page actually ends with Graphics.aspx. So I created the styles selectedStyle and unselectedStyle and gave it a shot. Note that this code is in the sitemaster though.
@David you are right, my mistake, use it like this: this.Page.ToString().ToLower().EndsWith("graphics_aspx") . Notice that I replace the dot with an underscore, and the page name is all lower case. I've updated the answer. Let me know how it goes.
@Reinaldo <li class="<%= this.Page.ToString().ToLower().EndsWith("graphics_aspx") ? "selectedStyle" : "unselectedStyle"%>"> <a href="\Graphics.aspx" target="_self"> Graphics</a></li> Does not seem to be working. Styles: .selectedStyle { border-right-style: solid; border-left-style: solid; border-right-color: #000000; border-left-color: #000000; color:Blue; } .unselectedStyle { color:Black; }
@David write this in your Master page and see what you get: '<%= this.Page.ToString().ToLower() %> Maybe you can change the condition to match the output.
|
0

You can either use the CSS active state if the page you are on directly relates to the link, however if the menu points to sections (i.e. multiple pages) you may need to use a bit of server side code to your master page, that gets the requested URL and determines which link is active. Usual convention is to then add the class 'active' or similar to the outputted html.

Comments

0

You can convert the UL/LI with runat = "server" and finally add styles in the code behind

Example

Control.Style.Add("display", "none");

3 Comments

"You can convert the UL/LI" what does that mean please? How and to what should I convert them?
Add runat server property in these tags and make it available in your code behind. Now add styles to that control.
<li><a href="\Graphics.aspx" target="_self" class="navmenustyle" id="graphicsMenu" runat="server"> Graphics</a></li> Does not work - still can't find the object "graphicsMenu" from my C# code.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.