LoginViewDesigner Class

Note: This class is new in the .NET Framework version 2.0.

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

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

public class LoginViewDesigner : ControlDesigner
public class LoginViewDesigner extends ControlDesigner
public class LoginViewDesigner extends ControlDesigner

The LoginView control renders one of its templates, determined by whether a user is logged on to the host Web site, and the roles that contain the logged-on user account.

In a visual designer, when you switch from Source to Design view, the markup source code that describes the LoginView 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 LoginViewDesigner class provides design-time support for the LoginView control.

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 TemplateGroups property returns a collection of template groups for the templates of the associated LoginView control. The UsePreviewControl property always returns true, indicating that the designer creates a temporary copy of the associated LoginView control to generate the design-time markup.

The LoginViewDesigner class methods provide the following functionality:

  • The GetDesignTimeHtml methods return the markup that is used to render the associated LoginView control at design time. The GetEmptyDesignTimeHtml method gets the markup that renders a placeholder for the associated control at design time when the current template is not defined. The GetErrorDesignTimeHtml method provides the markup that renders the associated control at design time when an error has occurred.

  • The GetEditableDesignerRegionContent method returns a serialized copy of the current template for the associated LoginView control. The SetEditableDesignerRegionContent method sets a region of the associated control from a serialized copy of a control template.

  • The Initialize method prepares the designer to view, edit, and design the associated LoginView control. The OnComponentChanged method is called when there is a change to the associated control. The PreFilterProperties method is used to remove properties from, add additional properties to, or shadow properties of the associated control.

The following code example shows how to extend the LoginViewDesigner class to change the appearance and behavior of controls that are derived from the LoginView control at design time.

The example derives the MyLoginView control from the LoginView. The MyLoginView is a copy of the LoginView control. The example also derives the MyLoginViewDesigner class from the LoginViewDesigner class and applies a DesignerAttribute attribute for the MyLoginViewDesigner on the MyLoginView control.

The MyLoginViewDesigner overrides the following LoginViewDesigner members:

  • The PreFilterProperties method to make the NamingContainer property visible in the Properties grid at design time.

  • The GetDesignTimeHtml method to draw an orange border around the control to make its extent more visible.

  • The GetErrorDesignTimeHtml method to generate the markup for a placeholder that includes the error message, which is rendered in red, bold text.

  • The GetEmptyDesignTimeHtml method to generate the markup for a placeholder that contains the names of the role groups that are defined for the control.

  • The Initialize method to throw an ArgumentException exception, if the associated control is not a MyLoginView object.

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

namespace Examples.CS.WebControls.Design
    // The MyLoginView is a copy of the LoginView.
        Level = AspNetHostingPermissionLevel.Minimal)]
        Level = AspNetHostingPermissionLevel.Minimal)]
    public class MyLoginView : LoginView
    } // MyLoginView

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

            return CreatePlaceHolderDesignTimeHtml(errorRendering);
        } // GetErrorDesignTimeHtml

        // Generate the design-time markup for the control 
        // when the template is empty.
        protected override string GetEmptyDesignTimeHtml()
            // Generate a design-time placeholder containing the names of all
            // the role groups.
            MyLoginView myLoginViewCtl = (MyLoginView)ViewControl;
            RoleGroupCollection roleGroups = myLoginViewCtl.RoleGroups;
            string roleNames = null;

            // If there are any role groups, form a string of their names.
            if (roleGroups.Count > 0)
                roleNames = "Role Groups: <br /> &nbsp;&nbsp;" + 

                for( int rgX = 1; rgX < roleGroups.Count; rgX++ )
                    roleNames += 
                        "<br /> &nbsp;&nbsp;" + roleGroups[rgX].ToString();
            return CreatePlaceHolderDesignTimeHtml( roleNames);
        } // GetEmptyDesignTimeHtml

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

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

        // Generate the design-time markup.
        public override string GetDesignTimeHtml(DesignerRegionCollection regions)
            // Make the control more visible in the designer.   
            // Enclose the markup in a table with an orange border. 
            const string openTableMarkup =
                "<table><tr><td style=\"border:4 solid #FF7F00;\">";
            const string closeTableMarkup = "</td></tr></table>";

            // Call the base method to generate the markup.
            string markup = base.GetDesignTimeHtml(regions);

            return openTableMarkup + markup + closeTableMarkup;

        } // GetDesignTimeHtml

        public override void Initialize(IComponent component)
            // Ensure that only a MyLoginView can be created in this designer.
            if (!(component is MyLoginView))
                throw new ArgumentException();

            // Call the base method to generate the markup.

        } // Initialize
    } // MyLoginViewDesigner
} // 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 2000 SP4, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

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

.NET Framework

Supported in: 2.0