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 6179907
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T00:45:07+00:00 2026-05-24T00:45:07+00:00

I am new the asp.net so i will appreciate a full code answer. I

  • 0

I am new the asp.net so i will appreciate a full code answer.

I have a web site in asp.net and c# i added a menu to the site.master page it looks like this:

<asp:Menu ID="mainMenu" runat="server" autopostback="true">
            <Items>
                <asp:MenuItem Text="Home" Value="Home" ></asp:MenuItem>
                <asp:MenuItem Text="Pipes" Value="Pipes"></asp:MenuItem>
                <asp:MenuItem Text="View &amp; Query" Value="View &amp; Query"></asp:MenuItem>
                <asp:MenuItem Text="API" Value="API"></asp:MenuItem>
            </Items>
        </asp:Menu>

I now need to add that when the user is on a specific page for example Pipes, then the right menuItem should have a different background color.

i can use a session variable but i am not sure how to do that.

Can any one please write for me a full example for this?

Thank you in advance

  • 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-24T00:45:08+00:00Added an answer on May 24, 2026 at 12:45 am

    You won’t need to track the page using session variables, as when you select a menu item, asp.net kindly tracks the item you’ve selected and generates its own CSS class for you (in most cases). To get a better visual download firebug for Firefox and look at the HTML output, you’ll see they’ll have CSS styles attached such as “asp-net.menu selectedItem” for example, you then create a .selectedItem{} CSS class, and then it will pick up the style automatically.

    However If I recall it can be a bit fiddly styling Microsoft controls, as if you check the source code out of the output, its not exactly HTML friendly.

    If you want to style the Menu item using the Microsoft approach, go here http://msdn.microsoft.com/en-us/library/ms366731.aspx

    However there is a library called CSSfriendly http://cssfriendly.codeplex.com/ that renders the control in pure HTML, which allows you to attach CSS classes much more easily. For example:

    .CssAdapterMenu ul.AspNet-Menu /* Tier 1 */
    {
        width: 961px !important;
        cursor:pointer;
        background-color:#000000;
    }
    
    .CssAdapterMenu ul.AspNet-Menu ul /* Tier 2 */
    {
        left: 0;
        background-color:#f8f8f8;
        width: 145% !important;
        max-width: 160px !important;
    }
    
    .CssAdapterMenu ul.AspNet-Menu ul li:hover /* Tier 2 cell */
    {
        background: #636363 url(../images/menu_bg_hover.png) no-repeat !important;
    }
    
    .CssAdapterMenu ul.AspNet-Menu ul .AspNet-Menu-Selected{
        background: transparent url(../images/menu_bg_hover.png) no-repeat !important;
    }
    
    .CssAdapterMenu li.AspNet-Menu-WithChildren li  .AspNet-Menu-ChildSelected {
        background: transparent url(../images/menu_bg_hover.png) no-repeat !important;
    }
    

    And so on and so forth. Theres good documentation out there for this, and its my preferred method for styling.

    Amended your code with my explanations below.

    <asp:Menu ID="mainMenu" runat="server" autopostback="true">
    <Items>
    <asp:MenuItem Text="Home" Value="Home" ></asp:MenuItem>
    <asp:MenuItem Text="Pipes" Value="Pipes"></asp:MenuItem>
    <asp:MenuItem Text="View &amp; Query" Value="View &amp; Query</asp:MenuItem>
    <asp:MenuItem Text="API" Value="API"></asp:MenuItem>
    </Items>
    <StaticMenuItemStyle CssClass="menuItem" />
    <StaticSelectedStyle CssClass="selectedItem" />
    <StaticHoverStyle CssClass="hoverItem" />
    </asp:Menu>
    

    Then in your CSS:

    .normal{ 
    background-color:#eaeaea; 
    } 
    
    .selected { 
    background-color:#000000; 
    }
    
    .hover{
    background-color:#FF0000; 
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am new to ASP.NET and building a financial web application. I have a
I have written an ASP.NET web page with C# behind that runs an existing
I'm planning a new ASP.NET project that will become a product that is installed
I'm using the new ASP.Net ListView control to list database items that will be
What will be the new features available in ASP.Net 4.0?
I wonder how long will an ASP.NET (MVC) application run, when no new requests
I deployed my ASP.NET application under an existing virtual directory. The new deployment will
My new ASP.NET MVC Web Application works on my development workstation, but does not
I create new ASP.NET web application that use SMTP to send message. The problem
I have a new ASP.NET MVC project (my first), and I had been running

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.