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 范围内的字母开头, (不区分大小写) ,下表中列出的特殊值除外,这些特殊值以下划线开头。
Value | 说明 |
---|---|
_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
属性。 如果 的呈现输出BulletedList必须符合 XHTML 1.1,请不要设置 Target 属性。 有关详细信息,请参阅主题 Visual Studio 中的 XHTML Standard 和 ASP.NET。
创建可访问的网页时,强烈建议避免使用 Target 属性来面向另一个窗口。 有关详细信息,请参阅 Visual Studio 和 ASP.NET 中的辅助功能。
此属性的值存储在视图状态中。
适用于
另请参阅
反馈
https://aka.ms/ContentUserFeedback。
即将发布:在整个 2024 年,我们将逐步淘汰作为内容反馈机制的“GitHub 问题”,并将其取代为新的反馈系统。 有关详细信息,请参阅:提交和查看相关反馈