ConnectionsZone 构造函数

定义

初始化 ConnectionsZone 类的新实例。Initializes a new instance of the ConnectionsZone class.

public:
 ConnectionsZone();
public ConnectionsZone ();
Public Sub New ()

示例

下面的代码示例演示如何使用 ConnectionsZone 构造函数创建 ConnectionsZone 要以编程方式添加到网页的控件的新实例。The following code example demonstrates the use of the ConnectionsZone constructor to create a new instance of a ConnectionsZone control to add to a Web page programmatically. 该示例只包含用于演示构造函数的网页的代码;对于运行此示例所需的其他两个代码文件,请参见类概述的 "示例" 部分 ConnectionsZoneThe example contains only the code for the Web page that demonstrates use of the constructor; for the other two code files needed to run the example, see the Example section of the ConnectionsZone class overview. 此代码示例包含四个部分:The code example has four parts:

  • 使您能够在网页上切换显示模式的用户控件。A user control that enables you to switch display modes on the Web page. 从类概述获取此代码 ConnectionsZoneObtain this code from the ConnectionsZone class overview.

  • 一个源文件,其中包含邮政编码接口的代码,以及两个控件, WebPart 用作连接的提供者和使用者。A source file that contains the code for a ZIP Code interface, and two WebPart controls acting as the provider and the consumer for a connection. 从类概述获取此代码 ConnectionsZoneObtain this code from the ConnectionsZone class overview.

  • 承载所有控件并且在其 Page_Init 方法中使用 ConnectionsZone 构造函数创建控件的新实例 ConnectionsZone 并将其添加到页中的网页。A Web page that hosts all the controls and, in its Page_Init method, uses the ConnectionsZone constructor to create a new instance of the ConnectionsZone control and add it to the page.

  • 说明如何在浏览器中工作。An explanation of how the example works in a browser.

在网页上,在方法中 Page_Init ,将 ConnectionsZone 使用构造函数) (创建新控件,并将其添加到页面中。On the Web page, in the Page_Init method, a new ConnectionsZone control is created (using the constructor) and added to the page. 当用户将页面设置为 "连接" 模式并单击其中一个控件上的 "连接" 谓词时 WebPartConnectionsZone 将显示一个控件。When a user sets the page to connect mode and clicks the connect verb on one of the WebPart controls, a ConnectionsZone control appears.

<%@ Page Language="C#" %>
<%@ register tagprefix="uc1" 
    tagname="DisplayModeMenuCS"
    src="~/displaymodemenucs.ascx" %>
<%@ Register TagPrefix="aspSample" 
    Namespace="Samples.AspNet.CS.Controls" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<script runat="server">
  protected void Page_Init(object sender, EventArgs e)
  {
    ConnectionsZone connZone = new ConnectionsZone();
    connZone.ID = "connectionsZone1";
    connZone.HeaderText = "Connections Zone 1";
    form1.Controls.AddAt(form1.Controls.Count - 1, connZone);
  }
</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>Connection Zone Sample</title>
</head>
<body>
  <form id="form1" runat="server">
  <asp:webpartmanager runat="server" id="mgr">
    <staticconnections>
      <asp:webpartconnection id="connection1" 
        consumerconnectionpointid="ZipCodeConsumer"
        consumerid="zipConsumer"
        providerconnectionpointid="ZipCodeProvider" 
        providerid="zipProvider" />
    </staticconnections>
  </asp:webpartmanager>
  <uc1:displaymodemenucs id="menu1" runat="server" />
  <div>
  <asp:webpartzone id="WebPartZone1" runat="server">
    <zonetemplate>
      <aspsample:zipcodewebpart id="zipProvider" runat="server" 
        Title="Zip Code Provider" />
      <aspsample:weatherwebpart id="zipConsumer" runat="server" 
        Title="Zip Code Consumer" />
    </zonetemplate>
  </asp:webpartzone>
  </div>
  </form>
</body>
</html>
<%@ Page Language="VB" %>
<%@ register tagprefix="uc1" 
    tagname="DisplayModeMenuVB"
    src="~/displaymodemenuvb.ascx" %>
<%@ Register TagPrefix="aspSample" 
    Namespace="Samples.AspNet.VB.Controls" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<script runat="server">

  Protected Sub Page_Init(ByVal sender As Object, _
    ByVal e As System.EventArgs)
    
    Dim connZone As ConnectionsZone = New ConnectionsZone()
    connZone.ID = "connectionsZone1"
    connZone.HeaderText = "Connections Zone 1"
    form1.Controls.AddAt(form1.Controls.Count - 1, connZone)

  End Sub
  
</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>Connection Zone Sample</title>
</head>
<body>
  <form id="form1" runat="server">
  <asp:webpartmanager runat="server" id="mgr">
    <staticconnections>
      <asp:webpartconnection id="connection1" 
        consumerconnectionpointid="ZipCodeConsumer"
        consumerid="zipConsumer"
        providerconnectionpointid="ZipCodeProvider" 
        providerid="zipProvider" />
    </staticconnections>
  </asp:webpartmanager>
  <uc1:displaymodemenuvb id="menu1" runat="server" />
  <div>
  <asp:webpartzone id="WebPartZone1" runat="server">
    <zonetemplate>
      <aspsample:zipcodewebpart id="zipProvider" runat="server" 
        Title="Zip Code Provider" />
      <aspsample:weatherwebpart id="zipConsumer" runat="server" 
        Title="Zip Code Consumer" />
    </zonetemplate>
  </asp:webpartzone>
  </div>
  </form>
</body>
</html>

在浏览器中加载页面。Load the page in a browser. 使用 " 显示模式 " 控件切换到 "连接" 模式。Switch to connect mode, using the Display Mode control. 单击 邮政编码提供程序 控件上的谓词菜单箭头,然后单击 "连接" 谓词。Click the verbs menu arrow on the ZIP Code Provider control, and click the connect verb. 连接 UI 随即出现,并且控件已连接,因为该连接是在页的标记中声明的。The connection UI appears, and the controls are already connected because the connection was declared in the markup of the page.

注解

在 ASP.NET 页中声明元素时,将调用此无参数的构造函数 <asp:connectionszone>This parameterless constructor is called when you declare the <asp:connectionszone> element in an ASP.NET page. 不需要隐式调用此构造函数,除非你以编程方式将控件添加到页面。You do not need to implicitly call this constructor, except in cases where you are adding the control to the page programmatically.

适用于