通过


MenuItemBinding.Target 属性

定义

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

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 属性指定在单击该菜单项时显示与菜单项关联的 Web 内容的窗口。 若要使此示例正常工作,必须将下面的示例 XML 数据复制到名为 Menu.xml的文件。


<%@ 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>MenuItemBinding Example</title>
</head>
<body>
    <form id="form1" runat="server">

      <h3>MenuItemBinding Example</h3>

      <asp:menu id="NavigationMenu"
        datasourceid="MenuSource"
        runat="server">
        
        <DataBindings>
        
          <asp:menuitembinding datamember="MapHomeNode"
            formatstring="({0})" 
            textfield="Title"
            valuefield="Description"
            imageurlfield="ImageUrl"
            tooltipfield="ToolTip"
            target="_self" />
          <asp:menuitembinding datamember="MapNode" 
            depth="1"
            formatstring="[{0}]" 
            textfield="Title"
            valuefield="Description"
            imageurlfield="ImageUrl"
            tooltipfield="ToolTip"
            target="_blank"/>
          <asp:menuitembinding datamember="MapNode" 
            depth="2"
            formatstring="<{0}>" 
            textfield="Title"
            valuefield="Description"
            imageurlfield="ImageUrl"
            tooltipfield="ToolTip"
            target="_blank"/>
          
        </DataBindings>
        
      </asp:menu>

      <asp:xmldatasource id="MenuSource"
        datafile="Menu.xml"
        runat="server"/> 

    </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>MenuItemBinding Example</title>
</head>
<body>
    <form id="form1" runat="server">

      <h3>MenuItemBinding Example</h3>

      <asp:menu id="NavigationMenu"
        datasourceid="MenuSource"
        runat="server">
        
        <DataBindings>
        
          <asp:menuitembinding datamember="MapHomeNode"
            formatstring="({0})" 
            textfield="Title"
            valuefield="Description"
            imageurlfield="ImageUrl"
            tooltipfield="ToolTip"
            target="_self" />
          <asp:menuitembinding datamember="MapNode" 
            depth="1"
            formatstring="[{0}]" 
            textfield="Title"
            valuefield="Description"
            imageurlfield="ImageUrl"
            tooltipfield="ToolTip"
            target="_blank"/>
          <asp:menuitembinding datamember="MapNode" 
            depth="2"
            formatstring="<{0}>" 
            textfield="Title"
            valuefield="Description"
            imageurlfield="ImageUrl"
            tooltipfield="ToolTip"
            target="_blank"/>
          
        </DataBindings>
        
      </asp:menu>

      <asp:xmldatasource id="MenuSource"
        datafile="Menu.xml"
        runat="server"/> 

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

以下代码是上一示例的示例站点地图数据。

<MapHomeNode ImageUrl="~\Images\Home.gif"

Title="Home"

Description="Root Page"

ToolTip="Home Page">

<MapNode ImageUrl="~\Images\Music.gif"

Title="Music"

Description="Music Category"

ToolTip="Music Page">

<MapNode ImageUrl="~\Images\Classical.gif"

Title="Classical"

Description="Classical Section"

ToolTip="Classical Page"/>

<MapNode ImageUrl="~\Images\Rock.gif"

Title="Rock"

Description="Rock Section"

ToolTip="Rock Page"/>

<MapNode ImageUrl="~\Images\Jazz.gif"

Title="Jazz"

Description="Jazz Section"

ToolTip="Jazz Page"/>

</MapNode>

<MapNode ImageUrl="~\Images\Movies.gif"

Title="Movies"

Description="Movies Category"

ToolTip="Movies Page">

<MapNode ImageUrl="~\Images\Action.gif"

Title="Action"

Description="Action Section"

ToolTip="Action Page"/>

<MapNode ImageUrl="~\Images\Drama.gif"

Title="Drama"

Description="Drama Section"

ToolTip="Drama Page"/>

<MapNode ImageUrl="~\Images\Musical.gif"

Title="Musical"

Description="Musical Section"

ToolTip="Musical Page"/>

</MapNode>

</MapHomeNode>

注解

Menu当控件绑定到数据源时,使用Target属性指定在单击该菜单项时显示链接到菜单项的 Web 内容的窗口或框架。

注释

设置此属性将Menu.Target覆盖应用对象的菜单项MenuItemBindingMenu控件的属性。 可以通过直接设置 MenuItem.Target 每个菜单项的属性来选择性地替代此属性。

目标值必须以 A 到 Z 范围内的字母开头(不区分大小写),但以下划线开头的某些特殊值除外,如下表所示。

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

注释

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

注释

Target 属性呈现为 target 属性。 target XHTML 1.1 文档类型定义中不允许元素上的anchor属性。 如果对象的呈现输出MenuItemBinding必须符合 XHTML 1.1,则不要设置Target该属性。 有关详细信息,请参阅 Visual Studio 中的 XHTML 标准主题和 ASP.NET

创建可访问的网页时,强烈建议避免使用属性 Target 来定位另一个窗口。 有关详细信息,请参阅 ASP.NET 辅助功能

适用于

另请参阅