After a menu node in sitemap in Asp.net is clicked, the connection is opened on this page by default, that is, the target of a is _ Self. Now we want some nodes to implement the target = _ blank effect, after thinking about it, since sitemap is XML, it should be able to customize attributes, so a target attribute is customized -- <sitemapnode url = "~ /. Aspx "target =" _ blank "Title =" AAA "Description =" "/>. In the repeater binding, <a href = '<% # eval (" url ") %> 'target = '<% # eval ("target") %>'>, the built-in sitemap reading class cannot read the Custom Attributes of sitemap,
You can use the description attribute <sitemapnode url = "~ /. Aspx "Title =" AAA "Description =" _ blank "/> binding: <a href = '<% # eval (" url ") %> 'target = '<% # eval ("Description") %>'>, found this method is really feasible.
On the internet to look at how others do, search a bit, found an article, http://www.wangchao.net.cn/bbsdetail_545376.html inside is achieved in this way
First, add custom attributes to the sitemap file. Here we use target <sitemapnode Title = "Homepage" Description = "" target = "_ blank" url = "~ /Default. aspx "/> then add the menuitemdatabound event processing code for the menu control.
Protected void mymenu_menuitemdatabound (Object sender, menueventargs E)
{
String target = (sitemapnode) E. Item. dataitem) ["target"];
If (target! = NULL & target. length> 0) E. Item. Target = target;
}
I did the same thing, even though I use repeater,
Write <sitemapnode url = "/a. aspx" target = "_ blank" Title = "test" Description = ""/>
The binding code is <a href = '<% # eval ("url") %>'>
The background writes this in the repeater event
Protected void repeater2_itemdatabound (Object sender, repeateritemeventargs E)
{
// Set CEO link as a new open form
String target = (sitemapnode) E. Item. dataitem) ["target"];
If (target! = NULL & target. length> 0)
{
String tempstring = "";
If (E. Item. hascontrols ())
{
// Get original control
System. Web. UI. databoundliteralcontrol origincontrol;
Origincontrol = E. Item. controls [0] As system. Web. UI. databoundliteralcontrol;
// Define a new control
System. Web. UI. databoundliteralcontrol tempcontrol = new databoundliteralcontrol (1, 1 );;
// Use old control's source string, and add target
Tempstring = origincontrol. Text. Replace ("<a href =", "<a target = '_ blank' href = ");
Tempcontrol. setdataboundstring (0, tempstring );
// Tempcontrol. setstaticstring (0, tempstring );
E. Item. Controls. Add (tempcontrol );
E. Item. Controls. Remove (origincontrol );
}
}
}