This documentation is archived and is not being maintained.

EditorPartDesigner Class

Provides design-time support for EditorPart controls.

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

[SecurityPermissionAttribute(SecurityAction.Demand, Flags = SecurityPermissionFlag.UnmanagedCode)]
public class EditorPartDesigner : PartDesigner

EditorPartDesigner is a public implementation of the PartDesigner base class for the purpose of rendering EditorPart controls at design time. It adds the capability of carrying zone information from the associated control into design view, but does not otherwise change the functionality of the parent control.

As with other control designers, you can change the design-time rendering of custom EditorPart controls by inheriting from EditorPartDesigner and overriding the GetDesignTimeHtml method. If you want to override the CreateViewControl method, be sure to include the base implementation so as to retain zone information.

The following code example creates a simple custom EditorPart control that allows the user to change the ToolTip property of the target control. The associated EditorPartDesigner validates the control and replaces the user input text box at design time with a label explaining that it is hidden.

using System;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.ComponentModel;
using System.Security.Permissions;
using System.Web.UI.Design.WebControls.WebParts;

/// <summary> 
/// SecretEditorPart is a custom EditorPart control that 
/// allows the end user to change the ToolTip property of 
/// a control by typing the value into a TextBox.  
/// SecretEditorPartDesigner hides the TextBox at design 
/// time via the view control and replaces it with the  
/// words "The textbox is now hidden." 
/// </summary> 
namespace Samples.AspNet.CS.Controls
{
    [Designer(typeof(SecretEditorPartDesigner))]
    public class SecretEditorPart : EditorPart
    {
        public CheckBox UseCustom = new CheckBox();
        public TextBox TTTextBox = new TextBox();

        protected override void CreateChildControls()
        {
            base.CreateChildControls();
            Controls.Add(UseCustom);
            Literal lApply = new Literal();
            lApply.Text = "Apply custom ToolTip<br />";
            Controls.Add(lApply);
            Controls.Add(TTTextBox);
        }

        public override bool ApplyChanges()
        {
            EnsureChildControls();
            try
            {
                WebPartToEdit.ToolTip = TTTextBox.Text;
            }
            catch
            {
                return false;
            }
            return true;
        }

        public override void SyncChanges()
        {
            // Abstract method not implemented for this example 
            return;
        }
    }

    public class SecretEditorPartDesigner : EditorPartDesigner
    {
        public override void Initialize(IComponent component)
        {
            // Validate the associated control 
            if (! (component is SecretEditorPart))
            {
                string msg = "The associated control must be of type 'SecretEditorPart'";
                throw new ArgumentException(msg);
            }
            base.Initialize(component);
        }

        public override string GetDesignTimeHtml()
        {
            // Access the view control.
            SecretEditorPart sep = (SecretEditorPart)ViewControl;

            // Hide the textbox.
            sep.TTTextBox.Visible = false;

            // Now generate the base rendering.
            string designTimeHtml = base.GetDesignTimeHtml();

            // Insert some text.
            string segment = "</div>";
            designTimeHtml = designTimeHtml.Replace(segment, 
                "The textbox is now hidden." + segment);

            // Return the modified rendering. 
            return designTimeHtml;
        }
    }
}

In order for the custom control to render, the page must have a WebPartManager control, an EditorZone with a ZoneTemplate for the control to reside in, and a WebPartZone containing a control for the custom EditorPart to act on, as shown in the following code example.

<%@ Page Language="C#" AutoEventWireup="true"  CodeFile="Default.aspx.cs" Inherits="_Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<%@ Register TagPrefix="ccl" Namespace="Samples.AspNet.CS.Controls" %>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>EditorPartDesigner Sample</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:WebPartManager ID="WebPartManager1" runat="server">
        </asp:WebPartManager><br />
        <asp:EditorZone ID="EditorZone1" runat="server" Enabled="true" >
            <ZoneTemplate>
                <ccl:SecretEditorPart ID="SEPart1" runat="server" />
            </ZoneTemplate>
        </asp:EditorZone>
        <asp:WebPartZone ID="WebPartZone1" runat="server">
            <ZoneTemplate>
                <asp:Button ID="Button1" runat="server" Height="24px" Text="Button" />
            </ZoneTemplate>
        </asp:WebPartZone><br />
    </div>
    </form>
</body>
</html>

For the EditorPart to be usable at run time, edit mode must be enabled on the page. The following code example demonstrates how to do so with a code-behind file.

using System;
using System.Web.UI.WebControls.WebParts;

public partial class _Default : System.Web.UI.Page 
{
    protected void Page_Load(object sender, EventArgs e)
    {
        {
            // Make the 'Edit' verb available so the EditorZone can render
            WebPartManager mgr = WebPartManager.GetCurrentWebPartManager(Page);
            mgr.DisplayMode = mgr.SupportedDisplayModes["Edit"];
        }
    }
}

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
Show: