共用方式為


Menu.Target 屬性

定義

取得或設定要顯示與功能表項目關聯之 Web 網頁內容的目標視窗或框架。

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 網頁內容的目標視窗或框架。 預設值是空字串 (""),會重新整理擁有焦點的視窗或框架。

範例

下列程式碼範例示範如何使用 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 在擁有焦點 (Focus) 的框架中呈現內容。
_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 和協助工具

適用於

另請參閱