BulletedList.Target 属性
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
获取或设置在单击控件中的 BulletedList 超链接时要在其中显示链接到的网页内容的目标窗口或框架。
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
属性值
在单击超链接 BulletedList 时加载链接到的网页的目标窗口或框架。 默认值为空字符串(“)。
- 属性
示例
下面的代码示例演示如何创建 BulletedList 控件并设置 Target 属性。 当用户从列表框中选择 HyperLink 显示模式时,属性 Target 设置为 _blank 在新浏览器窗口中显示链接页。
<%@ 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>DisplayMode Example</title>
<script runat="server">
void Index_Changed(object sender, System.EventArgs e)
{
// Change the message displayed, based on
// the display mode selected from the list box.
if (DisplayModeListBox.SelectedIndex > -1)
{
Message1.Text = "You chose: " + DisplayModeListBox.SelectedItem.Text;
}
// Change the display mode, based on
// the mode selected from the list box.
switch (DisplayModeListBox.SelectedIndex)
{
case 0:
ItemsBulletedList.DisplayMode = BulletedListDisplayMode.Text;
Message2.Text = "";
break;
case 1:
ItemsBulletedList.DisplayMode = BulletedListDisplayMode.HyperLink;
// Opens a new browser window to display the page linked to.
ItemsBulletedList.Target = "_blank";
Message2.Text = "";
break;
case 2:
ItemsBulletedList.DisplayMode = BulletedListDisplayMode.LinkButton;
break;
default:
throw new Exception("You did not select a valid display mode.");
break;
}
}
void ItemsBulletedList_Click(object sender, System.Web.UI.WebControls.BulletedListEventArgs e)
{
// Change the message displayed, based on the index
// of the bulletedlist list item that was clicked.
switch (e.Index)
{
case 0:
Message2.Text = "You clicked list item 1.";
break;
case 1:
Message2.Text = "You clicked list item 2.";
break;
case 2:
Message2.Text = "You clicked list item 3.";
break;
default:
throw new Exception("You did not click a valid list item.");
break;
}
}
</script>
</head>
<body>
<h3>DisplayMode Example</h3>
<form id="form1" runat="server">
<h3>BulletedListDisplayMode Example</h3>
<p>
<asp:BulletedList id="ItemsBulletedList"
BulletStyle="Disc"
DisplayMode="Text"
OnClick="ItemsBulletedList_Click"
runat="server">
<asp:ListItem Value="http://www.cohowinery.com">Coho Winery</asp:ListItem>
<asp:ListItem Value="http://www.contoso.com">Contoso, Ltd.</asp:ListItem>
<asp:ListItem Value="http://www.tailspintoys.com">Tailspin Toys</asp:ListItem>
</asp:BulletedList></p>
<hr />
<h4>Select from the list to change the display mode:</h4>
<asp:ListBox id="DisplayModeListBox"
Rows="1"
SelectionMode="Single"
AutoPostBack="True"
OnSelectedIndexChanged="Index_Changed"
runat="server">
<asp:ListItem>Text</asp:ListItem>
<asp:ListItem>Hyperlink</asp:ListItem>
<asp:ListItem>LinkButton</asp:ListItem>
</asp:ListBox>
<asp:Label id="Message1"
runat="server"
AssociatedControlID="DisplayModeListBox"/><br /><br />
<asp:Label id="Message2"
runat="server"
AssociatedControlID="DisplayModeListBox"/>
</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>DisplayMode Example</title>
<script runat="server">
Sub Index_Changed(ByVal sender As Object, ByVal e As System.EventArgs)
' Change the message displayed, based on
' the display mode selected from the list box.
If DisplayModeListBox.SelectedIndex > -1 Then
Message1.Text = "You chose: " & DisplayModeListBox.SelectedItem.Text
End If
' Change the display mode, based on
' the mode selected from the list box.
Select Case (DisplayModeListBox.SelectedIndex)
Case 0
ItemsBulletedList.DisplayMode = BulletedListDisplayMode.Text
Message2.Text = ""
Case 1
ItemsBulletedList.DisplayMode = BulletedListDisplayMode.HyperLink
' Opens a new browser window to display the page linked to.
ItemsBulletedList.Target = "_blank"
Message2.Text = ""
Case 2
ItemsBulletedList.DisplayMode = BulletedListDisplayMode.LinkButton
Case Else
Throw New Exception("You did not select a valid display mode.")
End Select
End Sub
Sub ItemsBulletedList_Click(ByVal sender As Object, _
ByVal e As System.Web.UI.WebControls.BulletedListEventArgs)
' Change the message displayed, based on the index
' of the bulletedlist list item that was clicked.
Select Case (e.Index)
Case 0
Message2.Text = "You clicked list item 1."
Case 1
Message2.Text = "You clicked list item 2."
Case 2
Message2.Text = "You clicked list item 3."
Case Else
Throw New Exception("You did not click a valid list item.")
End Select
End Sub
</script>
</head>
<body>
<h3>DisplayMode Example</h3>
<form id="form1" runat="server">
<h3>BulletedListDisplayMode Example</h3>
<p>
<asp:BulletedList id="ItemsBulletedList"
BulletStyle="Disc"
DisplayMode="Text"
OnClick="ItemsBulletedList_Click"
runat="server">
<asp:ListItem Value="http://www.cohowinery.com">Coho Winery</asp:ListItem>
<asp:ListItem Value="http://www.contoso.com">Contoso, Ltd.</asp:ListItem>
<asp:ListItem Value="http://www.tailspintoys.com">Tailspin Toys</asp:ListItem>
</asp:BulletedList></p>
<hr />
<h4>Select from the list to change the display mode:</h4>
<asp:ListBox id="DisplayModeListBox"
Rows="1"
SelectionMode="Single"
AutoPostBack="True"
OnSelectedIndexChanged="Index_Changed"
runat="server">
<asp:ListItem>Text</asp:ListItem>
<asp:ListItem>Hyperlink</asp:ListItem>
<asp:ListItem>LinkButton</asp:ListItem>
</asp:ListBox>
<asp:Label id="Message1"
runat="server"
AssociatedControlID="DisplayModeListBox"/><br /><br />
<asp:Label id="Message2"
runat="server"
AssociatedControlID="DisplayModeListBox"/>
</form>
</body>
</html>
注解
值必须以 A 到 Z 范围内的字母开头(不区分大小写),下表中列出的特殊值除外,以下划线开头。
| 价值 | 说明 |
|---|---|
_blank |
在不带框架的新窗口中呈现内容。 |
_parent |
呈现即时帧集父级中的内容。 |
_search |
在搜索窗格中呈现内容。 |
_self |
呈现具有焦点的帧中的内容。 |
_top |
在全窗口中呈现内容,而不显示框架。 |
注释
检查浏览器文档以确定值是否 _search 受支持。 例如,Microsoft Internet Explorer 5.0 及更高版本支持 _search 目标值。
使用该 Target 属性指定显示单击控件中的 BulletedList 超链接时链接到的网页的框架或窗口。 若要将列表项的内容显示为控件中的 BulletedList 超链接,请将 BulletedListDisplayMode 属性设置为值 HyperLink。 然后,将 Value 每个列表项的属性设置为要导航到的网页的 URL。
如果未设置该 Target 属性,则单击超链接时,具有焦点的浏览器或窗口将刷新。
注释
该 Target 属性呈现为 target 属性。
target XHTML 1.1 文档类型定义中不允许元素上的anchor属性。 如果呈现的 XHTML 1.1 输出符合 XHTML 1.1,BulletedList则不要设置Target该属性。 有关详细信息,请参阅 Visual Studio 中的 XHTML 标准主题和 ASP.NET。
创建可访问的网页时,强烈建议避免使用属性 Target 来定位另一个窗口。 有关详细信息,请参阅 Visual Studio 中的辅助功能和 ASP.NET。
此属性的值存储在视图状态中。