« ADO.NET Data Services - The server encountered an error | Main | The Denver IDEA Cafe Meetup »

Adding Target to ASP.NET Menu Control

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"];

        }

Posted on Wednesday, November 19, 2008 at 12:57PM by Registered CommenterDavid Yack | CommentsPost a Comment | References1 Reference

References (1)

References allow you to track sources for this article, as well as articles that were written in response to this article.
  • Response
    Response: blog hosting
    blog hosting [url=http://wordpress.com]blog hosting[/url] blog hosting [url= http://wordpress.com ] blog hosting [/url]

Reader Comments

There are no comments for this journal entry. To create a new comment, use the form below.

PostPost a New Comment

Enter your information below to add a new comment.

My response is on my own website »
Author Email (optional):
Author URL (optional):
Post:
 
Some HTML allowed: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <code> <em> <i> <strike> <strong>