Extended-> added the target attribute for the ASP. NET 2.0 Menu Control (menu, repeater ).

Source: Internet
Author: User

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 );
}
}
}

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.