HyperLinkField.Target 屬性
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
取得或設定目標視窗或框架,在按一下 HyperLinkField 物件中的超連結時,這個視窗或框架會顯示連結的網頁。
public:
virtual property System::String ^ Target { System::String ^ get(); void set(System::String ^ value); };
[System.ComponentModel.TypeConverter(typeof(System.Web.UI.WebControls.TargetConverter))]
public virtual string Target { get; set; }
[<System.ComponentModel.TypeConverter(typeof(System.Web.UI.WebControls.TargetConverter))>]
member this.Target : string with get, set
Public Overridable Property Target As String
屬性值
目標視窗或框架,在按一下 HyperLinkField 中的超連結時,這個視窗或框架會載入連結的網頁。 預設為空字串 (""),表示這個屬性未設定。
- 屬性
範例
下列程式碼範例示範如何使用 Target 屬性來指定目標視窗,以便顯示與 物件中 HyperLinkField 超連結相關聯的網頁內容。 按一下超連結時,連結的網頁會顯示在新視窗中。
<%@ 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>HyperLinkField Example</title>
</head>
<body>
<form id="form1" runat="server">
<h3>HyperLinkField Example</h3>
<!-- Populate the Columns collection declaratively. -->
<!-- Set the HyperLinkField field column to a static -->
<!-- caption and URL. -->
<asp:gridview id="OrdersGridView"
datasourceid="OrdersSqlDataSource"
autogeneratecolumns="false"
runat="server">
<columns>
<asp:boundfield datafield="OrderID"
headertext="OrderID"/>
<asp:boundfield datafield="CustomerID"
headertext="Customer ID"/>
<asp:boundfield datafield="OrderDate"
headertext="Order Date"
dataformatstring="{0:d}" />
<asp:hyperlinkfield text="Details..."
navigateurl="~\details.aspx"
headertext="Order Details"
target="_blank" />
</columns>
</asp:gridview>
<!-- This example uses Microsoft SQL Server and connects -->
<!-- to the Northwind sample database. -->
<asp:sqldatasource id="OrdersSqlDataSource"
selectcommand="SELECT [OrderID], [CustomerID], [OrderDate] FROM [Orders]"
connectionstring="server=localhost;database=northwind;integrated security=SSPI"
runat="server">
</asp:sqldatasource>
</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>HyperLinkField Example</title>
</head>
<body>
<form id="form1" runat="server">
<h3>HyperLinkField Example</h3>
<!-- Populate the Columns collection declaratively. -->
<!-- Set the HyperLinkField field column to a static -->
<!-- caption and URL. -->
<asp:gridview id="OrdersGridView"
datasourceid="OrdersSqlDataSource"
autogeneratecolumns="false"
runat="server">
<columns>
<asp:boundfield datafield="OrderID"
headertext="OrderID"/>
<asp:boundfield datafield="CustomerID"
headertext="Customer ID"/>
<asp:boundfield datafield="OrderDate"
headertext="Order Date"
dataformatstring="{0:d}" />
<asp:hyperlinkfield text="Details..."
navigateurl="~\details.aspx"
headertext="Order Details"
target="_blank" />
</columns>
</asp:gridview>
<!-- This example uses Microsoft SQL Server and connects -->
<!-- to the Northwind sample database. -->
<asp:sqldatasource id="OrdersSqlDataSource"
selectcommand="SELECT [OrderID], [CustomerID], [OrderDate] FROM [Orders]"
connectionstring="server=localhost;database=northwind;integrated security=SSPI"
runat="server">
</asp:sqldatasource>
</form>
</body>
</html>
備註
Target使用 屬性可指定視窗或框架,以在按一下超連結時顯示連結至超連結的 Web 內容。
值必須以 A 到 Z 範圍中的字母開頭, (不區分大小寫) ,但下表所列的特殊值除外,每個值都是以底線開頭。
值 | 描述 |
---|---|
_blank |
在無框架的新視窗中呈現內容。 |
_parent |
在即時父代框架組中呈現內容。 |
_search |
在搜尋窗格中呈現內容。 |
_self |
在擁有焦點 (Focus) 的框架中呈現內容。 |
_top |
在無框架的完整視窗中呈現內容。 |
注意
請查閱您的瀏覽器文件,以判斷是否支援 _search
值。 例如,Microsoft Internet Explorer 5.0 和更新版本支援 _search
目標值。
注意
屬性 Target 會轉譯為 target
屬性。 target
XHTML 1.1 檔案類型定義中不允許元素上的 anchor
屬性。 如果物件的轉譯輸出必須符合 XHTML 1.1 規範, HyperLinkField 請勿設定 Target 屬性。 如需詳細資訊,請參閱Visual Studio 和 ASP.NET 中的 XHTML 標準主題。
建立無障礙網頁時,強烈建議您避免使用 Target 屬性以另一個視窗為目標。 如需詳細資訊,請參閱ASP.NET 協助工具。