<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>NateElston.com &#187; ASP:Menu</title>
	<atom:link href="http://www.nateelston.com/wordpress/tag/aspmenu/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.nateelston.com/wordpress</link>
	<description>man. food. blog. adventures.</description>
	<lastBuildDate>Sat, 28 Aug 2010 12:59:07 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
	<div id='fb-root'></div>
				<script>
					window.fbAsyncInit = function()
					{
						FB.init({appId: null, status: true, cookie: true, xfbml: true});
					};
					(function()
					{
						var e = document.createElement('script'); e.async = true;
						e.src = document.location.protocol + '//connect.facebook.net/en_US/all.js';
						document.getElementById('fb-root').appendChild(e);
					}());
				</script>	
					<item>
		<title>ASP.Net Menu Control Open in New Window</title>
		<link>http://www.nateelston.com/wordpress/2009/06/aspnet-menu-control-open-in-new-window/</link>
		<comments>http://www.nateelston.com/wordpress/2009/06/aspnet-menu-control-open-in-new-window/#comments</comments>
		<pubDate>Thu, 18 Jun 2009 19:42:32 +0000</pubDate>
		<dc:creator>kozmo</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[ASP.Net]]></category>
		<category><![CDATA[ASP:Menu]]></category>
		<category><![CDATA[Microsoft]]></category>
		<category><![CDATA[Sitemap]]></category>
		<category><![CDATA[VB.Net]]></category>

		<guid isPermaLink="false">http://www.nateelston.com/wordpress/?p=50</guid>
		<description><![CDATA[Today I was presented with a problem that seemed simple enough, how do we make an ASP.Net Menu control open in a new window.  Sounds easy right, well that is what I thought.  But before I go too far, lets back up a minute and review what I am working with. Using ASP .Net 3.5 [...]]]></description>
			<content:encoded><![CDATA[<p>Today I was presented with a problem that seemed simple enough, how do we make an ASP.Net Menu control open in a new window.  Sounds easy right, well that is what I thought.  But before I go too far, lets back up a minute and review what I am working with.</p>
<p>Using ASP .Net 3.5 with VB.Net (C# would be preferred but someone started the app, besides it translates easy enough).</p>
<p>I have a .Net XML sitemap file:</p>

<div class="wp_codebox"><table><tr id="p506"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
</pre></td><td class="code" id="p50code6"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;?xml</span> <span style="color: #000066;">version</span>=<span style="color: #ff0000;">&quot;1.0&quot;</span> <span style="color: #000066;">encoding</span>=<span style="color: #ff0000;">&quot;utf-8&quot;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;siteMap</span> <span style="color: #000066;">xmlns</span>=<span style="color: #ff0000;">&quot;http://schemas.microsoft.com/AspNet/SiteMap-File-1.0&quot;</span> <span style="color: #000000; font-weight: bold;">&gt;</span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;siteMapNode</span> <span style="color: #000066;">url</span>=<span style="color: #ff0000;">&quot;Default.aspx&quot;</span> <span style="color: #000066;">title</span>=<span style="color: #ff0000;">&quot;Home&quot;</span>  <span style="color: #000066;">description</span>=<span style="color: #ff0000;">&quot;&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
&nbsp;
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;siteMapNode</span> <span style="color: #000066;">title</span>=<span style="color: #ff0000;">&quot;Membership&quot;</span></span>
<span style="color: #009900;">					 <span style="color: #000066;">url</span>=<span style="color: #ff0000;">&quot;~/Membership.aspx&quot;</span></span>
<span style="color: #009900;">					 <span style="color: #000066;">description</span>=<span style="color: #ff0000;">&quot;Membership Management&quot;</span></span>
<span style="color: #009900;">					 <span style="color: #000066;">roles</span>=<span style="color: #ff0000;">&quot;Admins&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
&nbsp;
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;siteMapNode</span> <span style="color: #000066;">url</span>=<span style="color: #ff0000;">&quot;CustomerSearch.aspx&quot;</span></span>
<span style="color: #009900;">					 <span style="color: #000066;">title</span>=<span style="color: #ff0000;">&quot;Customer Search&quot;</span></span>
<span style="color: #009900;">					 <span style="color: #000066;">description</span>=<span style="color: #ff0000;">&quot;Customer Search&quot;</span></span>
<span style="color: #009900;">					 <span style="color: #000066;">roles</span>=<span style="color: #ff0000;">&quot;Admins&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
&nbsp;
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;siteMapNode</span> <span style="color: #000066;">title</span>=<span style="color: #ff0000;">&quot;User&quot;</span> <span style="color: #000066;">description</span>=<span style="color: #ff0000;">&quot;Display/Search for user&quot;</span> <span style="color: #000066;">roles</span>=<span style="color: #ff0000;">&quot;IT&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
			<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;siteMapNode</span> <span style="color: #000066;">title</span>=<span style="color: #ff0000;">&quot;User Search&quot;</span></span>
<span style="color: #009900;">						 <span style="color: #000066;">url</span>=<span style="color: #ff0000;">&quot;~/userLookup.aspx&quot;</span></span>
<span style="color: #009900;">						 <span style="color: #000066;">description</span>=<span style="color: #ff0000;">&quot;Search for Users&quot;</span></span>
<span style="color: #009900;">						 <span style="color: #000066;">roles</span>=<span style="color: #ff0000;">&quot;Admins&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
&nbsp;
			<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;siteMapNode</span> <span style="color: #000066;">title</span>=<span style="color: #ff0000;">&quot;Create User&quot;</span></span>
<span style="color: #009900;">						 <span style="color: #000066;">url</span>=<span style="color: #ff0000;">&quot;http://external/createUser.asp?window=new&quot;</span></span>
<span style="color: #009900;">						 <span style="color: #000066;">description</span>=<span style="color: #ff0000;">&quot;Create a new user&quot;</span></span>
<span style="color: #009900;">						 <span style="color: #000066;">roles</span>=<span style="color: #ff0000;">&quot;Admins&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
      		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/siteMapNode<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;siteMapNode</span> <span style="color: #000066;">title</span>=<span style="color: #ff0000;">&quot;Logout&quot;</span></span>
<span style="color: #009900;">					 <span style="color: #000066;">url</span>=<span style="color: #ff0000;">&quot;~/Logout.aspx&quot;</span></span>
<span style="color: #009900;">					 <span style="color: #000066;">description</span>=<span style="color: #ff0000;">&quot;Logout&quot;</span></span>
<span style="color: #009900;">					 <span style="color: #000066;">roles</span>=<span style="color: #ff0000;">&quot;Admins&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
&nbsp;
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/siteMapNode<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/siteMap<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></td></tr></table></div>

<p>And an ASP.Net Menu control:</p>

<div class="wp_codebox"><table><tr id="p507"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
</pre></td><td class="code" id="p50code7"><pre class="asp" style="font-family:monospace;"><span style="color: #006600; font-weight: bold;">&lt;</span>asp<span style="color: #006600; font-weight: bold;">:</span>Menu ID<span style="color: #006600; font-weight: bold;">=</span><span style="color: #cc0000;">&quot;Menu1&quot;</span> runat<span style="color: #006600; font-weight: bold;">=</span><span style="color: #cc0000;">&quot;server&quot;</span> DataSourceID<span style="color: #006600; font-weight: bold;">=</span><span style="color: #cc0000;">&quot;SiteMapDataSource1&quot;</span> 
                            Orientation<span style="color: #006600; font-weight: bold;">=</span><span style="color: #cc0000;">&quot;Horizontal&quot;</span> BackColor<span style="color: #006600; font-weight: bold;">=</span><span style="color: #cc0000;">&quot;#E9E1EA&quot;</span><span style="color: #006600; font-weight: bold;">&gt;</span>
                        <span style="color: #006600; font-weight: bold;">&lt;</span>LevelMenuItemStyles<span style="color: #006600; font-weight: bold;">&gt;</span>
                            <span style="color: #006600; font-weight: bold;">&lt;</span>asp<span style="color: #006600; font-weight: bold;">:</span>MenuItemStyle CssClass<span style="color: #006600; font-weight: bold;">=</span><span style="color: #cc0000;">&quot;topMenuItem&quot;</span> Font-Bold<span style="color: #006600; font-weight: bold;">=</span><span style="color: #cc0000;">&quot;True&quot;</span> 
                                Font-Underline<span style="color: #006600; font-weight: bold;">=</span><span style="color: #cc0000;">&quot;False&quot;</span> ItemSpacing<span style="color: #006600; font-weight: bold;">=</span><span style="color: #cc0000;">&quot;25px&quot;</span> VerticalPadding<span style="color: #006600; font-weight: bold;">=</span><span style="color: #cc0000;">&quot;4px&quot;</span><span style="color: #006600; font-weight: bold;">/&gt;</span>
                        <span style="color: #006600; font-weight: bold;">&lt;/</span>LevelMenuItemStyles<span style="color: #006600; font-weight: bold;">&gt;</span>
                        <span style="color: #006600; font-weight: bold;">&lt;</span>DynamicHoverStyle BackColor<span style="color: #006600; font-weight: bold;">=</span><span style="color: #cc0000;">&quot;#E9E1EA&quot;</span> <span style="color: #006600; font-weight: bold;">/&gt;</span>
                    <span style="color: #006600; font-weight: bold;">&lt;/</span>asp<span style="color: #006600; font-weight: bold;">:</span>Menu<span style="color: #006600; font-weight: bold;">&gt;</span></pre></td></tr></table></div>

<p>This is what I was given from here, it was pretty simple once my brain started to function again, I fired an event as the menu item&#8217;s were bound, checked for a parameter in the url passed in from the site map and if it was present I added the target of   <em>&#8216;_blank&#8217; </em>to that menu item. And BOOM it worked, simple and a little more ghetto than I usually strive for but ultimatly an acceptable solution.  So here is what is looks like in code.</p>
<p>First thing you will notice is in my XML two of the menu item urls contain <em>&#8216;window=new&#8217;</em>, well this is the url parameter that my method is looking for, here is the XML in question:</p>

<div class="wp_codebox"><table><tr id="p508"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
</pre></td><td class="code" id="p50code8"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;siteMapNode</span> <span style="color: #000066;">title</span>=<span style="color: #ff0000;">&quot;User Search&quot;</span></span>
<span style="color: #009900;">		<span style="color: #000066;">url</span>=<span style="color: #ff0000;">&quot;~/userLookup.aspx&quot;</span></span>
<span style="color: #009900;">		<span style="color: #000066;">description</span>=<span style="color: #ff0000;">&quot;Search for Users&quot;</span></span>
<span style="color: #009900;">		<span style="color: #000066;">roles</span>=<span style="color: #ff0000;">&quot;Admins&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
&nbsp;
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;siteMapNode</span> <span style="color: #000066;">title</span>=<span style="color: #ff0000;">&quot;Create User&quot;</span></span>
<span style="color: #009900;">		 <span style="color: #000066;">url</span>=<span style="color: #ff0000;">&quot;http://external/createUser.asp?window=new&quot;</span></span>
<span style="color: #009900;">		 <span style="color: #000066;">description</span>=<span style="color: #ff0000;">&quot;Create a new user&quot;</span></span>
<span style="color: #009900;">		 <span style="color: #000066;">roles</span>=<span style="color: #ff0000;">&quot;Admins&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span></pre></td></tr></table></div>

<p>Once I got that figured out I added the event action to the ASP:</p>

<div class="wp_codebox"><table><tr id="p509"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
</pre></td><td class="code" id="p50code9"><pre class="asp" style="font-family:monospace;"><span style="color: #006600; font-weight: bold;">&lt;</span>asp<span style="color: #006600; font-weight: bold;">:</span>Menu ID<span style="color: #006600; font-weight: bold;">=</span><span style="color: #cc0000;">&quot;Menu1&quot;</span> runat<span style="color: #006600; font-weight: bold;">=</span><span style="color: #cc0000;">&quot;server&quot;</span> DataSourceID<span style="color: #006600; font-weight: bold;">=</span><span style="color: #cc0000;">&quot;SiteMapDataSource1&quot;</span> 
                            Orientation<span style="color: #006600; font-weight: bold;">=</span><span style="color: #cc0000;">&quot;Horizontal&quot;</span> BackColor<span style="color: #006600; font-weight: bold;">=</span><span style="color: #cc0000;">&quot;#E9E1EA&quot;</span> OnMenuItemDataBound<span style="color: #006600; font-weight: bold;">=</span><span style="color: #cc0000;">&quot;topMenu_menuItemDataBound&quot;</span> <span style="color: #006600; font-weight: bold;">&gt;</span>
                        <span style="color: #006600; font-weight: bold;">&lt;</span>LevelMenuItemStyles<span style="color: #006600; font-weight: bold;">&gt;</span>
                            <span style="color: #006600; font-weight: bold;">&lt;</span>asp<span style="color: #006600; font-weight: bold;">:</span>MenuItemStyle CssClass<span style="color: #006600; font-weight: bold;">=</span><span style="color: #cc0000;">&quot;topMenuItem&quot;</span> Font-Bold<span style="color: #006600; font-weight: bold;">=</span><span style="color: #cc0000;">&quot;True&quot;</span> 
                                Font-Underline<span style="color: #006600; font-weight: bold;">=</span><span style="color: #cc0000;">&quot;False&quot;</span> ItemSpacing<span style="color: #006600; font-weight: bold;">=</span><span style="color: #cc0000;">&quot;25px&quot;</span> VerticalPadding<span style="color: #006600; font-weight: bold;">=</span><span style="color: #cc0000;">&quot;4px&quot;</span><span style="color: #006600; font-weight: bold;">/&gt;</span>
                        <span style="color: #006600; font-weight: bold;">&lt;/</span>LevelMenuItemStyles<span style="color: #006600; font-weight: bold;">&gt;</span>
                        <span style="color: #006600; font-weight: bold;">&lt;</span>DynamicHoverStyle BackColor<span style="color: #006600; font-weight: bold;">=</span><span style="color: #cc0000;">&quot;#E9E1EA&quot;</span> <span style="color: #006600; font-weight: bold;">/&gt;</span>
                    <span style="color: #006600; font-weight: bold;">&lt;/</span>asp<span style="color: #006600; font-weight: bold;">:</span>Menu<span style="color: #006600; font-weight: bold;">&gt;</span></pre></td></tr></table></div>

<p>Once that was ready to go I wrote up the VB that lives behind the scenes, its pretty simple really:</p>

<div class="wp_codebox"><table><tr id="p5010"><td class="line_numbers"><pre>1
2
3
4
5
</pre></td><td class="code" id="p50code10"><pre class="vb" style="font-family:monospace;">Protected <span style="color: #000080;">Sub</span> topMenu_menuItemDataBound(<span style="color: #000080;">ByVal</span> sender <span style="color: #000080;">As</span> <span style="color: #000080;">Object</span>, <span style="color: #000080;">ByVal</span> e <span style="color: #000080;">As</span> MenuEventArgs) Handles Menu1.MenuItemDataBound
    <span style="color: #000080;">If</span> (e.Item.NavigateUrl.Contains(<span style="color: #800000;">&quot;window=new&quot;</span>)) <span style="color: #000080;">Then</span>
        e.Item.Target = <span style="color: #800000;">&quot;_blank&quot;</span>
    <span style="color: #000080;">End</span> <span style="color: #000080;">If</span>
<span style="color: #000080;">End</span> <span style="color: #000080;">Sub</span></pre></td></tr></table></div>

<p>There is probably a more elegant way to do this but for the time period I had and the need it was perfect, if we ever need to expand this I would probably just create my own sitemap that had target as an attribute and then build an alternative menu builder to take into account target.</p>
<div class='wpfblike'><fb:like href='http%3A%2F%2Fwww.nateelston.com%2Fwordpress%2F2009%2F06%2Faspnet-menu-control-open-in-new-window%2F' layout='button_count' show_faces='true' width='400' action='like' colorscheme='light' /></div>]]></content:encoded>
			<wfw:commentRss>http://www.nateelston.com/wordpress/2009/06/aspnet-menu-control-open-in-new-window/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
