Export (0) Print
Expand All

ProviderConnectionPoint.ProviderConnectionPoint Constructor

Initializes a new instance of the ProviderConnectionPoint class.

Namespace: System.Web.UI.WebControls.WebParts
Assembly: System.Web (in system.web.dll)

public ProviderConnectionPoint (
	MethodInfo callbackMethod,
	Type interfaceType,
	Type controlType,
	string displayName,
	string id,
	bool allowsMultipleConnections
)
public ProviderConnectionPoint (
	MethodInfo callbackMethod, 
	Type interfaceType, 
	Type controlType, 
	String displayName, 
	String id, 
	boolean allowsMultipleConnections
)
public function ProviderConnectionPoint (
	callbackMethod : MethodInfo, 
	interfaceType : Type, 
	controlType : Type, 
	displayName : String, 
	id : String, 
	allowsMultipleConnections : boolean
)
Not applicable.

Parameters

callbackMethod

The method in the provider control that returns an interface instance to consumers to establish a connection.

interfaceType

The Type of the interface that the provider serves to consumers.

controlType

The Type of the provider control with which the provider connection point is associated.

displayName

A friendly display name for the provider connection point that appears to users in the connection user interface (UI).

id

A unique identifier for the provider connection point.

allowsMultipleConnections

A Boolean value indicating whether the provider connection point can have multiple simultaneous connections with consumers.

Exception typeCondition

ArgumentNullException

callbackMethod is a null reference (Nothing in Visual Basic).

- or -

interfaceType is a null reference (Nothing in Visual Basic).

- or -

controlType is a null reference (Nothing in Visual Basic).

- or -

displayName is a null reference (Nothing in Visual Basic) or an empty string ("").

ArgumentException

controlType is not the same type as the provider control (or a valid class derived from it).

The ProviderConnectionPoint constructor for the ProviderConnectionPoint class simply calls the base constructor, passing to it the various parameters and initializing the base class.

The base class constructor checks a number of the parameters for a connection point and can throw several exceptions. For a list of possible exceptions, see the Exceptions section.

You can call the ProviderConnectionPoint constructor to create your own instance of the ProviderConnectionPoint class. However, in cases where you are simply establishing a connection and not extending the class, you should call the GetProviderConnectionPoints method to return an existing connection point object from a provider.

The following code example demonstrates how to derive from the ProviderConnectionPoint class to create a custom provider connection point.

The code example has three parts:

  • A source file that contains a provider WebPart control, a consumer WebPart control, and a custom ProviderConnectionPoint object.

  • A Web page that hosts the controls in a static connection.

  • An explanation of how to run the example code.

The first part of the code example is the source for the provider and consumer WebPart controls, and a custom ProviderConnectionPoint class, named TableProviderConnectionPoint. Note that the constructor of the TableProviderConnectionPoint class calls the base constructor, passing it the required parameters as indicated in the Parameters section. Also note that in the TableProviderWebPart class, the GetConnectionInterface method is specified as the callback method for connections, and the ConnectionProvider attribute declares the custom TableProviderConnectionPoint as a parameter. This demonstrates how to create a custom provider connection point and then associate it with a provider control. This example assumes that the source code is dynamically compiled, so you should place the source code file in an App_Code subfolder of your Web application.

using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Reflection;
using System.Web;
using System.Web.UI;
using System.Security.Permissions;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;

//This sample code creates a Web Parts control that acts as a provider of table data.
namespace Samples.AspNet.CS.Controls
{
  [AspNetHostingPermission(SecurityAction.Demand,
    Level = AspNetHostingPermissionLevel.Minimal)]
  [AspNetHostingPermission(SecurityAction.InheritanceDemand,
    Level = AspNetHostingPermissionLevel.Minimal)]
	public sealed class TableProviderWebPart : WebPart, IWebPartTable
	{
		DataTable _table;

		public TableProviderWebPart()
		{
			_table = new DataTable();

			DataColumn col = new DataColumn();
			col.DataType = typeof(string);
			col.ColumnName = "Name";
			_table.Columns.Add(col);

			col = new DataColumn();
			col.DataType = typeof(string);
			col.ColumnName = "Address";
			_table.Columns.Add(col);

			col = new DataColumn();
			col.DataType = typeof(int);
			col.ColumnName = "ZIP Code";
			_table.Columns.Add(col);

			DataRow row = _table.NewRow();
			row["Name"] = "John Q. Public";
			row["Address"] = "123 Main Street";
			row["ZIP Code"] = 98000;
			_table.Rows.Add(row);
		}

		public PropertyDescriptorCollection Schema
		{
			get
			{
				return TypeDescriptor.GetProperties(_table.DefaultView[0]);
			}
		}
		public void GetTableData(TableCallback callback)
		{
				callback(_table.Rows);
		}

		public bool ConnectionPointEnabled
		{
			get
			{
				object o = ViewState["ConnectionPointEnabled"];
				return (o != null) ? (bool)o : true;
			}
			set
			{
				ViewState["ConnectionPointEnabled"] = value;
			}
		}

		[ConnectionProvider("Table", typeof(TableProviderConnectionPoint), AllowsMultipleConnections = true)]
		public IWebPartTable GetConnectionInterface()
		{
			return new TableProviderWebPart();
		}

		public class TableProviderConnectionPoint : ProviderConnectionPoint
		{
			public TableProviderConnectionPoint(MethodInfo callbackMethod, Type interfaceType, Type controlType,
			string name, string id, bool allowsMultipleConnections) : base(
				callbackMethod, interfaceType, controlType,
				name, id, allowsMultipleConnections)
			{
			}
			public override bool GetEnabled(Control control)
			{
				return ((TableProviderWebPart)control).ConnectionPointEnabled;
			}
		}
	}
	
	// This code sample demonstrates a custom WebPart controls that acts as 
	// a consumer in a Web Parts connection.
  [AspNetHostingPermission(SecurityAction.Demand,
    Level = AspNetHostingPermissionLevel.Minimal)]
  [AspNetHostingPermission(SecurityAction.InheritanceDemand,
    Level = AspNetHostingPermissionLevel.Minimal)]
  public class TableConsumer : WebPart
  {
    private IWebPartTable _provider;
    private ICollection _tableData;

    private void GetTableData(object tableData)
    {
      _tableData = (ICollection)tableData;
    }

    protected override void OnPreRender(EventArgs e)
    {
      if (_provider != null)
      {
        _provider.GetTableData(new TableCallback(GetTableData));
      }
    }


    protected override void RenderContents(HtmlTextWriter writer)
    {
      if (_provider != null)
      {
        PropertyDescriptorCollection props = _provider.Schema;
        int count = 0;
        if (props != null && props.Count > 0 && _tableData != null)
        {
          foreach (PropertyDescriptor prop in props)
          {
            foreach (DataRow o in _tableData)
            {
              writer.Write(prop.DisplayName + ": " + o[count]);
            }
            writer.WriteBreak();
            writer.WriteLine();
            count = count + 1;
          }
        }
        else
        {
          writer.Write("No data");
        }
      }
      else
      {
        writer.Write("Not connected");
      }
    }
    [ConnectionConsumer("Table")]
    public void SetConnectionInterface(IWebPartTable provider)
    {
      _provider = provider;
    }

    public class TableConsumerConnectionPoint : ConsumerConnectionPoint
    {
      public TableConsumerConnectionPoint(MethodInfo callbackMethod, Type interfaceType, Type controlType,
      string name, string id, bool allowsMultipleConnections)
        : base(
        callbackMethod, interfaceType, controlType,
        name, id, allowsMultipleConnections)
      {
      }
    }
  }
}

The second part of the code example is the Web page that hosts the custom controls in a static Web Parts connection. At the top of the page is a Register directive to declare a prefix and the namespace for the custom controls. The connection is declared by using an <asp:webpartconnection> element, and the provider and consumer controls are declared within an <asp:webpartzone> element.

<%@ page language="C#" %>
<%@ 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">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>IField Test Page</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:webpartmanager id="WebPartManager1" runat="server">
            <StaticConnections>
                <asp:WebPartConnection id="wp1" ProviderID="provider1" ConsumerID="consumer1">
                </asp:WebPartConnection>
            </StaticConnections>
        </asp:webpartmanager>
        <asp:webpartzone id="WebPartZone1" runat="server">
          <zoneTemplate>
            <aspSample:TableProviderWebPart ID="provider1" runat="server" 
              ToolTip="Web Parts Table Provider Control" />
            <aspSample:TableConsumer ID="consumer1" runat="server" 
              ToolTip="Web Parts Table Consumer Control"/>
          </zoneTemplate>
        </asp:webpartzone>
    </div>
    </form>
</body>
</html>

Load the page in a browser. The connection between the controls already exists, and the consumer displays the data from the provider, because the connection was declared as a static connection in the page.

Windows 98, Windows Server 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

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0, 2.0

Community Additions

ADD
Show:
© 2014 Microsoft