Adding Target to ASP.NET Menu Control
Wednesday, November 19, 2008 at 12:57PM Out of the box the ASP.NET menu control doesn’t support setting a Target on a menu item. You can easily add support for this by adding a target node to the site map xml and then adding a event handler to set that on the menu item at data binding time.
So for example my siteMapNode would look like this with the target specified:
<siteMapNode title="New Property" description="New Property" url="Manage/Property/NewProperty.aspx" target="_blank" />
Then on the menu itself you would add an event handler to handle the MenuItemDataBound event. It would look like the following:
protected void Menu1_MenuItemDataBound(object sender, MenuEventArgs e)
{
SiteMapNode menuNode = (SiteMapNode)e.Item.DataItem;
if (menuNode["target"] != null)
e.Item.Target = menuNode["target"];
}
Reader Comments