Menu.Target 屬性

定義

取得或設定要顯示與功能表項目關聯之 Web 網頁內容的目標視窗或框架。Gets or sets the target window or frame in which to display the Web page content associated with a menu item.

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

屬性值

String

在其中顯示連結 Web 網頁內容的目標視窗或框架。The target window or frame in which to display the linked Web page content. 預設值是空字串 (""),會重新整理擁有焦點的視窗或框架。The default value is an empty string (""), which refreshes the window or frame with focus.

範例

下列程式碼範例示範如何使用屬性, Target 指定當使用者按一下功能表項目時,連結至每個功能表項目的內容應該顯示在新視窗中。The following code example demonstrates how to use the Target property to specify that the content linked to each menu item should be displayed in a new window when the user clicks that menu item.


<%@ 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 內容的視窗或框架。Use the Target property to specify the window or frame in which to display the Web content linked to a menu item when that menu item is clicked. 除了以底線為開頭的某些特殊值以外,值必須以 A 到 Z (不區分大小寫) 範圍內的字母為開頭,如下表所示。Values must begin with a letter in the range of A through Z (case-insensitive), except for certain special values that begin with an underscore, as shown in the following table.

目標值Target value 描述Description
_blank 在無框架的新視窗中呈現內容。Renders the content in a new window without frames.
_parent 在即時父代框架組中呈現內容。Renders the content in the immediate frameset parent.
_search 在搜尋窗格中呈現內容。Renders the content in the search pane.
_self 在擁有焦點 (Focus) 的框架中呈現內容。Renders the content in the frame with focus.
_top 在無框架的完整視窗中呈現內容。Renders the content in the full window without frames.

注意

請查閱您的瀏覽器文件,以判斷是否支援 _search 值。Check your browser documentation to determine if the _search value is supported. 例如,Internet Explorer 5.0 和更新版本支援 _search 目標值For example, Internet Explorer versions 5.0 and above support the _search target value

這個屬性會套用至控制項中的所有功能表項目 MenuThis property applies to all menu items in a Menu control. 您可以選擇性地覆寫這個屬性,方法是 Target 直接設定每個物件的屬性 MenuItemYou can selectively override this property by setting the Target property of each MenuItem object directly.

注意

Target屬性會呈現為目標屬性。The Target property renders as a target attribute. XHTML 1.1 嚴格檔案類型定義中不允許錨點元素上的目標屬性。The target attribute on anchor elements is not allowed in the XHTML 1.1 strict document type definition. 如果呈現的輸出必須符合 XHTML 或協助工具標準,請勿設定 Target 屬性。If rendered output must conform to XHTML or accessibility standards, do not set the Target property. 如需詳細資訊,請參閱 Visual Studio 中的XHTML 標準Visual Studio 和 ASP.NET 中的 ASP.NET 和協助工具。For more information, see XHTML Standards in Visual Studio and ASP.NET and Accessibility in Visual Studio and ASP.NET.

適用於

另請參閱