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 屬性指定在點擊該超連結時,顯示連結到該超連結的網頁內容的視窗或框架。
數值必須以A至Z範圍內的字母開頭(不區分大小寫),但下表列出的特殊值皆以底線開頭。
| 價值 | 說明 |
|---|---|
_blank |
它會在一個沒有框架的新視窗中渲染內容。 |
_parent |
將內容渲染到直接的框架集父節點。 |
_search |
在搜尋窗格中呈現內容。 |
_self |
能在畫面中聚焦渲染內容。 |
_top |
能在完整視窗中渲染內容,且不包含框架。 |
備註
請查看瀏覽器文件,確認該 _search 數值是否被支援。 例如,Microsoft Internet Explorer 5.0 及更新版本支援目標 _search 值。
備註
屬性 Target 會被呈現為屬性 target 。 XHTML 1.1 文件類型定義中不允許元素屬性targetanchor。 如果物件的渲染輸出HyperLinkField必須符合 XHTML 1.1,請不要設定該Target屬性。 欲了解更多資訊,請參閱 Visual Studio 與 ASP.NET 中的 XHTML 標準主題。
在建立無障礙網頁時,強烈建議避免使用該 Target 屬性來指向其他視窗。 更多資訊請參閱 ASP.NET 無障礙。