HyperLinkField.Target 属性

定义

获取或设置目标窗口或框架,单击 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 将内容呈现在含焦点的框架中。
_top 将内容呈现在没有框架的全窗口中。

注意

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

注意

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

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

适用于

另请参阅