ConnectionsZone 建構函式
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
初始化 ConnectionsZone 類別的新執行個體。
public:
ConnectionsZone();
public ConnectionsZone();
Public Sub New ()
範例
以下程式碼範例示範如何使用 ConnectionsZone 建構子建立新的控制項實例 ConnectionsZone ,以程式化地新增到網頁中。 範例僅包含網頁程式碼,示範建構子的使用;關於執行範例所需的另外兩個程式碼檔案,請參見類別總覽的 ConnectionsZone 範例部分。 程式碼範例包含四個部分:
一個使用者控制功能,讓你能在網頁上切換顯示模式。 此代碼可從 ConnectionsZone 職業總覽取得。
一個包含 ZIP 編碼介面程式碼的原始碼檔案,以及兩個 WebPart 作為連線提供者與消費者的控制項。 此代碼可從 ConnectionsZone 職業總覽取得。
一個承載所有控制項的
Page_Init網頁,並以其方法使用 ConnectionsZone 建構子建立新的控制項實例 ConnectionsZone 並將其加入頁面。說明這個範例在瀏覽器中如何運作。
在網頁上,方法 Page_Init 中會建立一個新的 ConnectionsZone 控制項(使用建構子)並加入頁面。 當使用者將頁面設為連接模式,並點擊其中一個 WebPart 控制項上的連接動詞時,會顯示一個 ConnectionsZone 控制項。
<%@ 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>
在瀏覽器中載入該頁面。 切換到連接模式,使用 顯示模式 控制。 點擊郵 遞區號提供者 控制項上的動詞選單箭頭,然後點選「連結動詞」。 連線介面會出現,且控制項已經連接,因為連線是在頁面標記中宣告的。
備註
這個無參數建構器會在你宣告 ASP.NET 頁面中宣告 <asp:connectionszone> 元素時被呼叫。 除非你是以程式方式將控制項加入頁面,否則你不需要隱含呼叫這個建構子。