注意:此字段在 .NET Framework 2.0 版中是新增的。
表示用于显示特殊用户界面 (UI) 以便用户管理
WebPart 控件之间的连接的显示模式。此字段为只读。
命名空间:System.Web.UI.WebControls.WebParts
程序集:System.Web(在 system.web.dll 中)
Public Shared ReadOnly ConnectDisplayMode As WebPartDisplayMode
Dim value As WebPartDisplayMode
value = WebPartManager.ConnectDisplayMode
public static readonly WebPartDisplayMode ConnectDisplayMode
public:
static initonly WebPartDisplayMode^ ConnectDisplayMode
public static final WebPartDisplayMode ConnectDisplayMode
public static final var ConnectDisplayMode : WebPartDisplayMode
ConnectDisplayMode 字段引用一个自定义 WebPartDisplayMode 对象,该对象由 WebPartManager 控件创建,并包含在该控件中。因为这是一个静态对象,所以可以通过 WebPartManager 类直接引用它,而无需该控件的实例。
用户要管理某一网页上 WebPart 控件之间的连接时,如果已在该页上声明了一个 ConnectionsZone 区域,则可将该页切换至 ConnectDisplayMode 模式。连接显示模式显示一个用于管理连接的特殊用户界面,该界面可用来连接控件或断开控件连接,以及编辑现有连接的详细信息。
如果要使用户能够使用由 Web 部件控件集提供的用户界面管理连接,必须在页标记中声明一个 <asp:connectionszone> 元素。与其他类型的 WebZone 区域的元素不同,您不必在此元素内添加任何其他标记;您只需声明该元素本身。
下面的代码示例演示 ConnectDisplayMode 模式的用法。
该代码示例包括三部分:
该代码示例的第一部分是一个源文件,其中包含一个接口和两个设计为可以连接的自定义 WebPart 控件。必须编译此源代码,代码示例才能运行。可以显式编译源代码,并将结果程序集放在网站的 Bin 文件夹或全局程序集缓存中。另外,也可将源代码放入站点的 App_Code 文件夹中,源代码将在运行时在此文件夹中进行动态编译。此代码示例使用动态编译方法。有关演示如何编译的演练,请参见 演练:开发和使用自定义服务器控件。
Imports System
Imports System.Web
Imports System.Web.Security
Imports System.Security.Permissions
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports System.Web.UI.WebControls.WebParts
Namespace Samples.AspNet.VB.Controls
<AspNetHostingPermission(SecurityAction.Demand, _
Level:=AspNetHostingPermissionLevel.Minimal)> _
<AspNetHostingPermission(SecurityAction.InheritanceDemand, _
Level:=AspNetHostingPermissionLevel.Minimal)> _
Public Interface IZipCode
Property ZipCode() As String
End Interface
<AspNetHostingPermission(SecurityAction.Demand, _
Level:=AspNetHostingPermissionLevel.Minimal)> _
<AspNetHostingPermission(SecurityAction.InheritanceDemand, _
Level:=AspNetHostingPermissionLevel.Minimal)> _
Public Class ZipCodeWebPart
Inherits WebPart
Implements IZipCode
Private zipCodeText As String = String.Empty
Private input As TextBox
Private send As Button
Public Sub New()
End Sub
' Make the implemented property personalizable to save
' the Zip Code between browser sessions.
<Personalizable()> _
Public Property ZipCode() As String _
Implements IZipCode.ZipCode
Get
Return zipCodeText
End Get
Set(ByVal value As String)
zipCodeText = value
End Set
End Property
' This is the callback method that returns the provider.
<ConnectionProvider("Zip Code", "ZipCodeProvider")> _
Public Function ProvideIZipCode() As IZipCode
Return Me
End Function
Protected Overrides Sub CreateChildControls()
Controls.Clear()
input = New TextBox()
Me.Controls.Add(input)
send = New Button()
send.Text = "Enter 5-digit Zip Code"
AddHandler send.Click, AddressOf Me.submit_Click
Me.Controls.Add(send)
End Sub
Private Sub submit_Click(ByVal sender As Object, _
ByVal e As EventArgs)
If input.Text <> String.Empty Then
zipCodeText = Page.Server.HtmlEncode(input.Text)
input.Text = String.Empty
End If
End Sub
End Class
<AspNetHostingPermission(SecurityAction.Demand, _
Level:=AspNetHostingPermissionLevel.Minimal)> _
<AspNetHostingPermission(SecurityAction.InheritanceDemand, _
Level:=AspNetHostingPermissionLevel.Minimal)> _
Public Class WeatherWebPart
Inherits WebPart
Private _provider As IZipCode
Private _zipSearch As String
Private DisplayContent As Label
' This method is identified by the ConnectionConsumer
' attribute, and is the mechanism for connecting with
' the provider.
<ConnectionConsumer("Zip Code", "ZipCodeConsumer")> _
Public Sub GetIZipCode(ByVal Provider As IZipCode)
_provider = Provider
End Sub
Protected Overrides Sub OnPreRender(ByVal e As EventArgs)
EnsureChildControls()
If Not (Me._provider Is Nothing) Then
_zipSearch = _provider.ZipCode.Trim()
DisplayContent.Text = "My Zip Code is: " + _zipSearch
End If
End Sub 'OnPreRender
Protected Overrides Sub CreateChildControls()
Controls.Clear()
DisplayContent = New Label()
Me.Controls.Add(DisplayContent)
End Sub
End Class
End Namespace
namespace Samples.AspNet.CS.Controls
{
using System;
using System.Web;
using System.Web.Security;
using System.Security.Permissions;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
[AspNetHostingPermission(SecurityAction.Demand,
Level = AspNetHostingPermissionLevel.Minimal)]
[AspNetHostingPermission(SecurityAction.InheritanceDemand,
Level = AspNetHostingPermissionLevel.Minimal)]
public interface IZipCode
{
string ZipCode { get; set;}
}
[AspNetHostingPermission(SecurityAction.Demand,
Level = AspNetHostingPermissionLevel.Minimal)]
[AspNetHostingPermission(SecurityAction.InheritanceDemand,
Level = AspNetHostingPermissionLevel.Minimal)]
public class ZipCodeWebPart : WebPart, IZipCode
{
string zipCodeText = String.Empty;
TextBox input;
Button send;
public ZipCodeWebPart()
{
}
// Make the implemented property personalizable to save
// the Zip Code between browser sessions.
[Personalizable()]
public virtual string ZipCode
{
get { return zipCodeText; }
set { zipCodeText = value; }
}
// This is the callback method that returns the provider.
[ConnectionProvider("Zip Code", "ZipCodeProvider")]
public IZipCode ProvideIZipCode()
{
return this;
}
protected override void CreateChildControls()
{
Controls.Clear();
input = new TextBox();
this.Controls.Add(input);
send = new Button();
send.Text = "Enter 5-digit Zip Code";
send.Click += new EventHandler(this.submit_Click);
this.Controls.Add(send);
}
private void submit_Click(object sender, EventArgs e)
{
if (input.Text != String.Empty)
{
zipCodeText = Page.Server.HtmlEncode(input.Text);
input.Text = String.Empty;
}
}
}
[AspNetHostingPermission(SecurityAction.Demand,
Level = AspNetHostingPermissionLevel.Minimal)]
[AspNetHostingPermission(SecurityAction.InheritanceDemand,
Level = AspNetHostingPermissionLevel.Minimal)]
public class WeatherWebPart : WebPart
{
private IZipCode _provider;
string _zipSearch;
Label DisplayContent;
// This method is identified by the ConnectionConsumer
// attribute, and is the mechanism for connecting with
// the provider.
[ConnectionConsumer("Zip Code", "ZipCodeConsumer")]
public void GetIZipCode(IZipCode Provider)
{
_provider = Provider;
}
protected override void OnPreRender(EventArgs e)
{
EnsureChildControls();
if (this._provider != null)
{
_zipSearch = _provider.ZipCode.Trim();
DisplayContent.Text = "My Zip Code is: " + _zipSearch;
}
}
protected override void CreateChildControls()
{
Controls.Clear();
DisplayContent = new Label();
this.Controls.Add(DisplayContent);
}
}
}
该示例的第二部分是一个包含自定义控件的网页。在页上的服务器 <script> 标记内有几个方法,这些方法使用页上可用的显示模式填充一个下拉列表。用户可从该下拉列表进行选择来更改页的显示模式。由于在页的标记中声明了一个 <asp:connectionszone> 元素,所以连接显示模式是可用的显示模式之一。注意,此元素不包含任何其他子元素;其存在只是为了使用户能够使用连接管理用户界面。
在此示例中,ConnectDisplayMode 模式在两个位置出现。第一个位置在 Page_Init 方法中,连接显示模式在代码依次通过 SupportedDisplayModes 属性中引用的集合时添加到显示模式下拉列表中。第二个位置,Page_PreRender 方法检查页上的当前显示模式,如果当前模式是 ConnectDisplayMode,则在 Label 控件中显示一条消息。
<%@ Page Language="vb" %>
<%@ Register TagPrefix="aspSample"
Namespace="Samples.AspNet.VB.Controls" %>
<script runat="server">
Protected Sub Page_Init(ByVal sender As Object, _
ByVal e As EventArgs)
Dim mode As WebPartDisplayMode
For Each mode In mgr.SupportedDisplayModes
Dim modeName As String = mode.Name
If mode.IsEnabled(mgr) Then
Dim item As ListItem = New ListItem(modeName, modeName)
DisplayModeDropdown.Items.Add(item)
End If
Next
End Sub
Protected Sub DisplayModeDropdown_SelectedIndexChanged(ByVal _
sender As Object, ByVal e As EventArgs)
Dim selectedMode As String = _
DisplayModeDropdown.SelectedValue
Dim mode As WebPartDisplayMode = _
mgr.SupportedDisplayModes(selectedMode)
If mode IsNot Nothing Then
mgr.DisplayMode = mode
End If
End Sub
Protected Sub Page_PreRender(ByVal sender As Object, _
ByVal e As System.EventArgs)
If mgr.DisplayMode.Equals(WebPartManager.ConnectDisplayMode) Then
Label1.Visible = True
Else
Label1.Visible = False
End If
End Sub
</script>
<html >
<head id="Head1" runat="server">
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:WebPartManager ID="mgr" runat="server" />
<asp:Label ID="Label1" runat="server"
Text="Currently in Connect Display Mode"
Font-Bold="true"
Font-Size="125%" />
<br />
<asp:DropDownList ID="DisplayModeDropdown"
runat="server"
AutoPostBack="true"
Width="120"
OnSelectedIndexChanged=
"DisplayModeDropdown_SelectedIndexChanged">
</asp:DropDownList>
<hr />
<asp:WebPartZone ID="WebPartZone1" runat="server">
<ZoneTemplate>
<aspSample:ZipCodeWebPart ID="zip1" runat="server"
Title="Zip Code Provider" />
<aspSample:WeatherWebPart ID="weather1" runat="server"
Title="Zip Code Consumer" />
</ZoneTemplate>
</asp:WebPartZone>
<asp:ConnectionsZone ID="ConnectionsZone1" runat="server" />
</div>
</form>
</body>
</html>
<%@ Page Language="C#" %>
<%@ Register TagPrefix="aspSample"
Namespace="Samples.AspNet.CS.Controls" %>
<script runat="server">
protected void Page_Init(object sender, EventArgs e)
{
foreach (WebPartDisplayMode mode in mgr.SupportedDisplayModes)
{
string modeName = mode.Name;
if (mode.IsEnabled(mgr))
{
ListItem item = new ListItem(modeName, modeName);
DisplayModeDropdown.Items.Add(item);
}
}
}
protected void DisplayModeDropdown_SelectedIndexChanged(object
sender, EventArgs e)
{
String selectedMode = DisplayModeDropdown.SelectedValue;
WebPartDisplayMode mode =
mgr.SupportedDisplayModes[selectedMode];
if (mode != null)
mgr.DisplayMode = mode;
}
protected void Page_PreRender(object sender, EventArgs e)
{
if (mgr.DisplayMode == WebPartManager.ConnectDisplayMode)
Label1.Visible = true;
else
Label1.Visible = false;
}
</script>
<html >
<head runat="server">
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:WebPartManager ID="mgr" runat="server" />
<asp:Label ID="Label1" runat="server"
Text="Currently in Connect Display Mode"
Font-Bold="true"
Font-Size="125%" />
<br />
<asp:DropDownList ID="DisplayModeDropdown"
runat="server"
AutoPostBack="true"
Width="120"
OnSelectedIndexChanged=
"DisplayModeDropdown_SelectedIndexChanged">
</asp:DropDownList>
<hr />
<asp:WebPartZone ID="WebPartZone1" runat="server">
<ZoneTemplate>
<aspSample:ZipCodeWebPart ID="zip1" runat="server"
Title="Zip Code Provider" />
<aspSample:WeatherWebPart ID="weather1" runat="server"
Title="Zip Code Consumer" />
</ZoneTemplate>
</asp:WebPartZone>
<asp:ConnectionsZone ID="ConnectionsZone1" runat="server" />
</div>
</form>
</body>
</html>
将该页加载到浏览器中之后,单击该下拉列表并选择“连接”,将该页切换至连接显示模式。注意,会显示一条消息,通知您该页处于连接显示模式。现在单击 WebPart 控件之一的标题栏中的谓词菜单(一个箭头符号),然后单击谓词菜单中的“连接”。显示连接用户界面之后,单击链接创建一个连接。使用显示的连接用户界面中的下拉列表选择将参与连接的另一控件,然后单击“连接”按钮。随即建立连接。单击“关闭”按钮,然后使用页顶部的下拉列表将该页返回浏览显示模式。
Windows 98、Windows 2000 SP4、Windows Millennium Edition、Windows Server 2003、Windows XP Media Center Edition、Windows XP Professional x64 Edition、Windows XP SP2、Windows XP Starter Edition
.NET Framework 并不是对每个平台的所有版本都提供支持。有关受支持版本的列表,请参见系统要求。
.NET Framework
受以下版本支持:2.0