ControlDesigner.Initialize Method

Initializes the control designer and loads the specified component.

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

public override void Initialize(
	IComponent component
)

Parameters

component
Type: System.ComponentModel.IComponent

The control being designed.

Implements

IDesigner.Initialize(IComponent)

The Initialize method is called by the design host to complete the following actions:

  • Load the control designer with the component to design.

  • Set up the view on the control using the SetViewFlags method.

  • Verify that the associated control is of the right type.

The following code example demonstrates how to use a control class and a control designer class that override the Initialize method to initialize internal variables.

using System;
using System.ComponentModel;
using System.Web.UI;
using System.Web.UI.Design;
using System.Web.UI.WebControls;

namespace AspNet.Samples
{
    // Create a custom class to render the Text property
    [Designer(typeof(SimpleDesigner)), DefaultProperty("Text"), 
    ToolboxData("<{0}:Simple runat=\"server\"></{0}:Simple>")]
    public sealed class Simple : WebControl
    {
        public Simple()
        { }

        // Create a Text property
        [Browsable(true), Bindable(true), 
            PersistenceMode(PersistenceMode.Attribute)]
        public string Text
        {
            get
            {
                object o = ViewState["TextProp"];
                return (o == null) ? "Sample Text" : (string)o;
            }
            set { ViewState["TextProp"] = value; }
        }

        // Render the text inside the control 
        protected override void RenderContents(HtmlTextWriter writer)
        {
            writer.Write(Text);
        }
    }
}

namespace AspNet.Samples
{
    //Create a designer class for the Simple control 
    public sealed class SimpleDesigner : ControlDesigner
    {
        // Declare a reference to the Simple class 
        private Simple simpleControl;

        public SimpleDesigner()
        { }

        public override void Initialize(IComponent ponent)
        {
            base.Initialize(ponent);

            // Get a reference to the control
            simpleControl = (Simple)ponent;

            //Set Text to the control's ID
            simpleControl.Text = simpleControl.ID;
        }

        // Allow resizing the control in the design host 
        public override bool AllowResize
        {
            get
            {
                return true;
            }
        }

        public override string GetDesignTimeHtml()
        {
            if (simpleControl.Text.Length > 0)
            {
                string spec = "<a href='{0}.aspx'>{0}</a>";
                return String.Format(spec, simpleControl.Text);
            }
            else 
                return GetEmptyDesignTimeHtml();
        }
    }
}

.NET Framework

Supported in: 4.5, 4, 3.5, 3.0, 2.0, 1.1, 1.0

Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

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

Was this page helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft