Export (0) Print
Expand All

LoginDesigner Class

Provides design-time support in a visual designer for the Login Web-server control.

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

public class LoginDesigner : CompositeControlDesigner
public class LoginDesigner extends CompositeControlDesigner
public class LoginDesigner extends CompositeControlDesigner
Not applicable.

The Login control displays a user interface that allows a user to log on to the host Web site.

In a visual designer, when you switch from Source to Design view, the markup source code that describes the Login control is parsed and a design-time version of the control is created on the design surface. When you switch back to Source view, the design-time control is persisted to the markup source code and edited into the markup for the Web page. The LoginDesigner class provides design-time support for the Login control.

The LoginDesigner class properties provide the following functionality:

  • The ActionLists property returns a DesignerActionListCollection object, which typically contains an object that is derived from the DesignerActionList class for each level in the inheritance tree of the designer.

  • The AutoFormats property returns a collection of formatting schemes for display in the Auto Format dialog box.

  • The TemplateGroups property returns a collection of template groups for the fields of the associated Login control and the top-level Login template.

  • The UsePreviewControl property always returns true, indicating that the designer creates a temporary copy of the associated Login to generate the design-time markup.

The LoginDesigner class methods provide the following functionality:

  • The GetDesignTimeHtml method returns the markup that is used to render the associated Login at design time.

  • The GetEditableDesignerRegionContent method returns a serialized copy of the template for the associated Login.

  • The GetErrorDesignTimeHtml method provides the markup that is used to render the associated Login at design time when an error has occurred.

  • The Initialize method prepares the designer to view, edit, and design the associated Login.

  • The PreFilterProperties method is used to remove properties from, add additional properties to, or shadow properties of the associated Login.

  • The SetEditableDesignerRegionContent method sets a region of the associated Login from a serialized copy of a control template.

The following code example shows how to extend the LoginDesigner class to change the appearance of controls that are derived from the Login control at design time.

The example derives the MyLogin control from the Login. The MyLogin is a copy of the Login control. The example also derives the MyLoginDesigner class from the LoginDesigner and applies a DesignerAttribute attribute for the MyLoginDesigner on the MyLogin control.

The MyLoginDesigner overrides the PreFilterProperties method to make the NamingContainer property visible in the Properties grid at design time. It overrides the GetDesignTimeHtml method to draw a blue, dashed border around the control to make its extent more visible, if the BorderStyle property of the MyLogin control is the NotSet or None value. It overrides the GetErrorDesignTimeHtml method to generate the markup for a placeholder that includes the error message rendered in red, bold text.

using System;
using System.Web;
using System.Drawing;
using System.Web.UI.WebControls;
using System.Web.UI.Design.WebControls;
using System.Collections;
using System.ComponentModel;
using System.Security.Permissions;

namespace Examples.CS.WebControls.Design
{
    // The MyLogin is a copy of the Login.
    [AspNetHostingPermission(SecurityAction.Demand, 
        Level = AspNetHostingPermissionLevel.Minimal)]
    [AspNetHostingPermission(SecurityAction.InheritanceDemand, 
        Level = AspNetHostingPermissionLevel.Minimal)]
    [Designer(typeof(Examples.CS.WebControls.Design.MyLoginDesigner))]
    public class MyLogin : Login
    {
    } // MyLogin

    // Override members of the LoginDesigner.
    [ReflectionPermission(SecurityAction.Demand, Flags=ReflectionPermissionFlag.MemberAccess)]
    public class MyLoginDesigner : LoginDesigner
    {
        // Generate the design-time markup for the control when an error occurs.
        protected override string GetErrorDesignTimeHtml(Exception e) 
        {
            // Write the error message text in red, bold.
            string errorRendering =
                "<span style=\"font-weight:bold; color:Red; \">" +
                e.Message + "</span>";

            return CreatePlaceHolderDesignTimeHtml(errorRendering);
        } // GetErrorDesignTimeHtml

        // Shadow the control properties with design-time properties.
        protected override void PreFilterProperties(IDictionary properties)
        {
            // Call the base method first.
            base.PreFilterProperties(properties);

            // Make the NamingContainer visible in the Properties grid.
            PropertyDescriptor selectProp = 
                (PropertyDescriptor)properties["NamingContainer"];
            properties["NamingContainer"] =
                TypeDescriptor.CreateProperty(selectProp.ComponentType, 
                    selectProp, BrowsableAttribute.Yes);
        } // PreFilterProperties

        // Generate the design-time markup.
        public override string GetDesignTimeHtml()
        {
            // Make the control more visible in the designer.  If the border 
            // style is None or NotSet, change the border to a blue dashed line. 
            MyLogin myLoginCtl = (MyLogin)ViewControl;
            string markup = null;

            // Check if the border style should be changed.
            if (myLoginCtl.BorderStyle == BorderStyle.NotSet ||
                myLoginCtl.BorderStyle == BorderStyle.None)
            {
                BorderStyle oldBorderStyle = myLoginCtl.BorderStyle;
                Color oldBorderColor = myLoginCtl.BorderColor;

                // Set the design time properties and catch any exceptions.
                try
                {
                    myLoginCtl.BorderStyle = BorderStyle.Dashed;
                    myLoginCtl.BorderColor = Color.Blue;

                    // Call the base method to generate the markup.
                    markup = base.GetDesignTimeHtml();
                }
                catch (Exception ex)
                {
                    markup = GetErrorDesignTimeHtml(ex);
                }
                finally
                {
                    // It is not necessary to restore the border properties 
                    // to their original values because the ViewControl 
                    // was used to reference the associated control and the 
                    // UsePreviewControl was not overridden.  

                    // myLoginCtl.BorderStyle = oldBorderStyle;
                    // myLoginCtl.BorderColor = oldBorderColor;
                }
            }
            else
                // Call the base method to generate the markup.
                markup = base.GetDesignTimeHtml();

            return markup;

        } // GetDesignTimeHtml
    } // MyLoginDesigner
} // Examples.CS.WebControls.Design

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