Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 556099
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T11:53:02+00:00 2026-05-13T11:53:02+00:00

I’m having some trouble with my main menu on my ASP.NET website. What I

  • 0

I’m having some trouble with my main menu on my ASP.NET website. What I want is, when a user clicks on a link, it should change it’s color to black and remain black until the user clicks on the other links.

In other words: I want to highlight the selected link.

So far I’ve got it working using some workaround JavaScript (should consider using jQuery instead I think), but the problem is, that the style dosn’t remain on page postback (or so it seems..)

My current javascript:

<script type="text/javascript">
    var last = "none";
    function LinkSelector(link) {
        if (last != "none") {
            document.getElementById(last).className = "NormalLink";
        }
        document.getElementById(link).className = "ActiveLink";
        last = link;
    }
</script>

As I wrote, it sure changes the class name when clicked, but dosn’t remain that way when the new page is loaded.

Anyone got a workaround on this? 🙂

Thanks in advance.

All the best,

Bo

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T11:53:02+00:00Added an answer on May 13, 2026 at 11:53 am

    Typically, I’ll use the ASP:Menu control. It provides a decent amount of control over the menu items in it.

    For example, here’s a generic method that I dump in a masterpage and run during the initial page hit. This method loops over the menu items in the menu control, and selects the menu item that corresponds to the current URL.

    protected void Page_Load(object sender, EventArgs e) {
            if (!Page.IsPostBack) {
                SelectMenuItem();
            }
        }
    
        private void SelectMenuItem() {
                string rawurl = Request.RawUrl.ToLower();
    
                rawurl = rawurl.Substring(rawurl.LastIndexOf("/") + 1);
                if (rawurl.IndexOf("?") >= 0)
                    rawurl = rawurl.Substring(0, rawurl.IndexOf("?"));
    
                foreach (MenuItem mi in mnuMain.Items) {
                    if (mi.ChildItems.Count == 0) {
                        if (mi.Value == rawurl) {
                            mi.Selected = true;
                            break;
                        }
                    }
                    else {
                        foreach (MenuItem cmi in mi.ChildItems) {
                            if (cmi.Value == rawurl) {
                                mi.Selected = true;
                                break;
                            }
                        }
                        if (mi.Selected)
                            break;
                    }
                }
            }
    

    Here are a few of the menu items I have in my asp menu control. Note that I use the Value attribute to help me indicate which menu item pertains to the requested URL in the method above.

    <Items>
      <asp:MenuItem Text="Forms" Value="authorization">
        <asp:MenuItem Text="New Authorization Form" Value="createauthform.aspx" NavigateUrl="~/CreateAuthForm.aspx"></asp:MenuItem>
        <asp:MenuItem Text="Manage My Authorization Forms" Value="myrequests.aspx" NavigateUrl="~/MyRequests.aspx"></asp:MenuItem>
        <asp:MenuItem Text="Audit Attendance Form" Value="auditform.aspx" NavigateUrl="~/AuditForm.aspx"></asp:MenuItem>
        <asp:MenuItem Text="Tax Determination Statement" Value="taxstatement.aspx"  NavigateUrl="~/TaxStatement.aspx"></asp:MenuItem>
      </asp:MenuItem>
    </Items>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I'm having trouble keeping the paragraph square between the quote marks. In firefox the
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but
For some reason, after submitting a string like this Jack’s Spindle from a text
I used javascript for loading a picture on my website depending on which small
I have a French site that I want to parse, but am running into
I want use html5's new tag to play a wav file (currently only supported
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.