This documentation is archived and is not being maintained.

WebPartTransformer Class

Provides basic implementation for transformer classes to convert data between two incompatible connection points.

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

<AspNetHostingPermissionAttribute(SecurityAction.InheritanceDemand, Level := AspNetHostingPermissionLevel.Minimal)> _
<AspNetHostingPermissionAttribute(SecurityAction.LinkDemand, Level := AspNetHostingPermissionLevel.Minimal)> _
Public MustInherit Class WebPartTransformer
Dim instance As WebPartTransformer

Transformers are used to translate data between two Web Parts controls with incompatible connection points. Connection points are incompatible when they provide or consume data through different interfaces. For example, a provider implementing a provider connection point of type IWebPartRow could not directly connect to a consumer expecting a provider connection point of type IWebPartTable. Instead, a transformer must be used to connect the two Web Parts controls.

The transformer accepts data of the type supported by the provider connection point. It does the necessary internal processing to convert that data into the type supported by the consumer connection point.

A transformer can provide a user interface (UI) that allows the user to configure the transformer when in the connect mode. The configuration control is retrieved through the CreateConfigurationControl method and is displayed in a Web Parts connections zone.

WebPartTransformer is an abstract class and must be extended to provide customized translations between different types of connection points.

Notes to Inheritors:

You must override the Transform method.

The following code example demonstrates how to create a customized transformer that derives from the WebPartTransformer class. The transformer, named RowToStringTransformer, allows for a Web Parts provider and Web Parts consumer with incompatible connection points to be connected. The provider presents data of type IWebPartRow, but the consumer accepts only data of type String. The RowToStringTransformer class performs the necessary conversion.

The code example does not include an implementation of the provider or consumer. You must create a provider that implements the IWebPartRow interface and a consumer that expects data through a customized interface named IString for the example to work.

' An interface that the transformer provides to the consumer.
<AspNetHostingPermission(SecurityAction.Demand, _
   Level:=AspNetHostingPermissionLevel.Minimal)> _
<AspNetHostingPermission(SecurityAction.InheritanceDemand, _
   Level:=AspNetHostingPermissionLevel.Minimal)> _
Public Interface IString
    Sub GetStringValue(ByVal callback As StringCallback)
End Interface

The first section of the code example contains code for the provider and consumer Web Parts controls, and the code for the transformer.

' A transformer that transforms a row to a string.
<AspNetHostingPermission(SecurityAction.Demand, _
   Level:=AspNetHostingPermissionLevel.Minimal)> _
<AspNetHostingPermission(SecurityAction.InheritanceDemand, _
   Level:=AspNetHostingPermissionLevel.Minimal)> _
<WebPartTransformer(GetType(IWebPartRow), GetType(IString))> _
Public Class RowToStringTransformer
    Inherits WebPartTransformer
    Implements IString

    Private _provider As IWebPartRow
    Private _callback As StringCallback

    Private Sub GetRowData(ByVal rowData As Object)
        Dim props As PropertyDescriptorCollection = _provider.Schema

        If ((Not (props Is Nothing)) AndAlso (props.Count > 0) _
          AndAlso (Not (rowData Is Nothing))) Then 
            Dim returnValue As String = String.Empty
            For Each prop As PropertyDescriptor In props
                If Not (prop Is props(0)) Then
                    returnValue += ", " 
                End If
                returnValue += prop.DisplayName.ToString() + ": " + _
        End If 
    End Sub 

    Public Overrides Function Transform(ByVal providerData As Object) As Object
        _provider = CType(providerData, IWebPartRow)
        Return Me 
    End Function 

    Sub GetStringValue(ByVal callback As StringCallback) _
       Implements IString.GetStringValue
        If (callback Is Nothing) Then 
            Throw New ArgumentNullException("callback")
        End If 

        If (Not (_provider Is Nothing)) Then
            _callback = callback
            _provider.GetRowData(New RowCallback(AddressOf GetRowData))
        End If 
    End Sub 
End Class

The second section of the code example shows how to include the transformer within the declarative syntax for a WebPartConnection object.

<%@ Page Language="VB" %>
<%@ register tagprefix="uc1" 
    src="~/displaymodemenuvb.ascx" %>
<%@ Register TagPrefix="wp" 
    NameSpace="Samples.AspNet.VB.Controls" %>

<script runat="server">


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"  

<html xmlns="" >
    <title>Web Parts Transformers Sample Page</title>
<form id="Form1" runat="server">

<asp:webpartmanager id="manager" runat="server">
    <asp:webpartconnection id="conn1" providerid="p1" consumerid="c1">
      <wp:rowtostringtransformer />
<uc1:displaymodemenuvb id="menu1" runat="server" />

<tr valign="top">
  <asp:webpartzone id="zone1" headertext="zone1" runat="server">
      <wp:rowproviderwebpart id="p1" runat="server" />
      <wp:stringconsumerwebpart id="c1" runat="server" />
  <asp:connectionszone id="connectionszone1" runat="server" />


A customized transformer must be specified in the <transformers> section of the Web.config file to be available for use in a Web page. The third section of the code example shows how to add the customized transformer to the Web.config file.

[Visual Basic]

<webParts enableExport="true">
       <add name="RowToStringTransformer"
          type="Samples.AspNet.VB.Controls.RowToStringTransformer" />


<webParts enableExport="true">
       <add name="RowToStringTransformer"
          type="Samples.AspNet.CS.Controls.RowToStringTransformer" />

The code example includes a user control that enables you to change display modes on a Web Parts page. The source code for the user control comes from another topic. You can obtain the .ascx file for the user control from Walkthrough: Changing Display Modes on a Web Parts Page, and it must be placed in the same folder as the .aspx page.

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Windows 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98

The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

.NET Framework

Supported in: 3.5, 3.0, 2.0