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.
I think you must set the selected item on MenuItemDataBound event (adapt your code):
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:
In web.sitemap, add a ? character to the url:
In code behind, capture the MenuItemDataBound event:
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
OK, here's what I ended up with. (Thanks, Leniel, for pointing me in the right direction.) The following code is in the code behind of the master file that contains the menu control. Comments in the code reveal my surprise that this control doesn't allow multiple items to be selected at one time. So, in a multi-level menu, I couldn't show as selected both the current node and it's parent. (Unless I'm missing something.)
If your web.sitemap file contains external links (links to other domains), then those links will need to start with http:// or https://, but your local file references would not - they would just be relative references from the current location of the loaded document.
As such, there's no need to pad your URL's with extra characters, when the characters you need are already there (http or https).
If you have a local file that you want opened in a new window, just change the URL from a local reference to the full URL (it will take that file slightly longer to load because the URL will have to resolve).