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

  • Home
  • SEARCH
  • 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 762301
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T15:56:29+00:00 2026-05-14T15:56:29+00:00

ASP.NET newbie here. When on a page I’d like to set the corresponding menu

  • 0

ASP.NET newbie here. When on a page I’d like to set the corresponding menu item to selected. My approach is this:
On Home.aspx.cs:

Menu menu = (Menu)Master.FindControl("Menu1");

if (menu.Items.Count > 0)
{
    menu.FindItem("Home").Selected = true;
}

Trouble is, menu.item.count == 0 .
My menu is bound to a sitemap, if that matters.

  • 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-14T15:56:30+00:00Added an answer on May 14, 2026 at 3:56 pm

    I think you must set the selected item on MenuItemDataBound event (adapt your code):

    protected void Menu1_MenuItemDataBound(object sender, MenuEventArgs e)
    {
        if (SiteMap.CurrentNode != null)
        {
            if (e.Item.Text == SiteMap.CurrentNode.Title)
            {
                e.Item.Selected = true;
            }
        }
    }
    

    More content that shows how to handle links in a menu that has as datasource a sitemap…

    To have a menu link built from web.sitemap open in new window…

    In asp.net page add OnMenuItemDataBound event:

    <asp:Menu ID="mnuFooter" runat="server"
    DataSourceID="SiteMapDataSource1"
    OnMenuItemDataBound="mnuFooter_MenuItemDataBound">
    </asp:Menu>
    

    In web.sitemap, add a ? character to the url:

    In code behind, capture the MenuItemDataBound event:

    protected void mnuFooter_MenuItemDataBound(Object sender, MenuEventArgs e)
    {
        if (e.Item.NavigateUrl.Contains("?"))
        {
            e.Item.Target = "_blank";
        }
    }
    

    Any url in the web.sitemap that contains a ? will open in a new window. Note, use any other valid url character in place of the ? if necessary.

    ASP.NET Menu Control Overview

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

ASP.NET newbie here. I would like to create a form with multiple types of
ASP.NET server-side controls postback to their own page. This makes cases where you want
ASP.NET newbie here I have coded up an ASP.NET website and running on win'08
AJAX newbie here! At the moment in my ASP.NET MVC web app my AJAX
I am a complete ASP .NET newbie. I've written a set of web services
Possible Duplicate: ASP.NET “special” tags I hope this isn't too much of a newbie
I'm newbie in ASP.NET I have a page to show a thread content, it
This is probably again a newbie question. When I create an ASP.NET MVC2 application,
ASP.NET newbie question - fastest fingers! I have a page that needs to pull
ASP.NET MVC newbie question: I've set up a MVC site, with a few controllers.

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.