通过


Menu.Target 属性

定义

获取或设置要在其中显示与菜单项关联的网页内容的目标窗口或框架。

public:
 property System::String ^ Target { System::String ^ get(); void set(System::String ^ value); };
public string Target { get; set; }
member this.Target : string with get, set
Public Property Target As String

属性值

要在其中显示链接网页内容的目标窗口或框架。 默认值为空字符串(“”),用于刷新具有焦点的窗口或框架。

示例

下面的代码示例演示如何使用 Target 属性指定当用户单击该菜单项时,应在新窗口中显示链接到每个菜单项的内容。


<%@ Page Language="C#" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
  <head runat="server">
    <title>Menu Target Example</title>
</head>
<body>
    <form id="form1" runat="server">
    
      <h3>Menu Target Example</h3>
    
      <asp:menu id="NavigationMenu"
        staticdisplaylevels="2"
        staticsubmenuindent="10" 
        orientation="Vertical"
        target="_blank"  
        runat="server">

        <items>
          <asp:menuitem navigateurl="Home.aspx" 
            text="Home"
            tooltip="Home">
            <asp:menuitem navigateurl="Music.aspx"
              text="Music"
              tooltip="Music">
              <asp:menuitem navigateurl="Classical.aspx" 
                text="Classical"
                tooltip="Classical"/>
              <asp:menuitem navigateurl="Rock.aspx"
                text="Rock"
                tooltip="Rock"/>
              <asp:menuitem navigateurl="Jazz.aspx"
                text="Jazz"
                tooltip="Jazz"/>
            </asp:menuitem>
            <asp:menuitem navigateurl="Movies.aspx"
              text="Movies"
              tooltip="Movies">
              <asp:menuitem navigateurl="Action.aspx"
                text="Action"
                tooltip="Action"/>
              <asp:menuitem navigateurl="Drama.aspx"
                text="Drama"
                tooltip="Drama"/>
              <asp:menuitem navigateurl="Musical.aspx"
                text="Musical"
                tooltip="Musical"/>
            </asp:menuitem>
          </asp:menuitem>
        </items>
      
      </asp:menu>

    </form>
  </body>
</html>

<%@ Page Language="VB" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
  <head runat="server">
    <title>Menu Target Example</title>
</head>
<body>
    <form id="form1" runat="server">
    
      <h3>Menu Target Example</h3>
    
      <asp:menu id="NavigationMenu"
        staticdisplaylevels="2"
        staticsubmenuindent="10" 
        orientation="Vertical"
        target="_blank"  
        runat="server">

        <items>
          <asp:menuitem navigateurl="Home.aspx" 
            text="Home"
            tooltip="Home">
            <asp:menuitem navigateurl="Music.aspx"
              text="Music"
              tooltip="Music">
              <asp:menuitem navigateurl="Classical.aspx" 
                text="Classical"
                tooltip="Classical"/>
              <asp:menuitem navigateurl="Rock.aspx"
                text="Rock"
                tooltip="Rock"/>
              <asp:menuitem navigateurl="Jazz.aspx"
                text="Jazz"
                tooltip="Jazz"/>
            </asp:menuitem>
            <asp:menuitem navigateurl="Movies.aspx"
              text="Movies"
              tooltip="Movies">
              <asp:menuitem navigateurl="Action.aspx"
                text="Action"
                tooltip="Action"/>
              <asp:menuitem navigateurl="Drama.aspx"
                text="Drama"
                tooltip="Drama"/>
              <asp:menuitem navigateurl="Musical.aspx"
                text="Musical"
                tooltip="Musical"/>
            </asp:menuitem>
          </asp:menuitem>
        </items>
      
      </asp:menu>

    </form>
  </body>
</html>

注解

使用该 Target 属性可以指定在单击该菜单项时显示链接到菜单项的 Web 内容的窗口或框架。 值必须以 A 到 Z 范围内的字母开头(不区分大小写),但以下划线开头的某些特殊值除外,如下表所示。

目标值 说明
_blank 在不带框架的新窗口中呈现内容。
_parent 呈现即时帧集父级中的内容。
_search 在搜索窗格中呈现内容。
_self 呈现具有焦点的帧中的内容。
_top 在全窗口中呈现内容,而不显示框架。

注释

检查浏览器文档以确定值是否 _search 受支持。 例如,Internet Explorer 版本 5.0 及更高版本支持 _search 目标值

此属性适用于控件中的所有 Menu 菜单项。 可以通过直接设置 Target 每个 MenuItem 对象的属性来选择性地替代此属性。

注释

Target 属性呈现为目标属性。 XHTML 1.1 严格文档类型定义中不允许定位点元素上的目标属性。 如果呈现的输出必须符合 XHTML 或辅助功能标准,请不要设置 Target 属性。 有关详细信息,请参阅 Visual Studio 中的 XHTML 标准,以及 Visual Studio 中的 ASP.NET辅助功能以及 ASP.NET

适用于

另请参阅