LoginViewDesigner Class
Collapse the table of content
Expand the table of content

LoginViewDesigner Class

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)

<SecurityPermissionAttribute(SecurityAction.Demand, Flags := SecurityPermissionFlag.UnmanagedCode)> _
Public Class LoginViewDesigner _
	Inherits ControlDesigner
Dim instance As LoginViewDesigner

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 control 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.

Imports System
Imports System.Web
Imports System.Web.UI.WebControls
Imports System.Web.UI.Design
Imports System.Web.UI.Design.WebControls
Imports System.Collections
Imports System.ComponentModel
Imports System.Security.Permissions
Imports System.IO

Namespace Examples.VB.WebControls.Design

    ' The MyLoginView is a copy of the LoginView.
    <AspNetHostingPermission(SecurityAction.Demand, _
        Level:=AspNetHostingPermissionLevel.Minimal)> _
    <AspNetHostingPermission(SecurityAction.InheritanceDemand, _
        Level:=AspNetHostingPermissionLevel.Minimal)> _
    <Designer(GetType(Examples.VB.WebControls.Design.MyLoginViewDesigner))> _
    Public Class MyLoginView
        Inherits LoginView
    End Class ' MyLoginView

    ' Override members of the LoginViewDesigner.
    <ReflectionPermission(SecurityAction.Demand, Flags:=ReflectionPermissionFlag.MemberAccess)> _
    Public Class MyLoginViewDesigner
        Inherits LoginViewDesigner

        ' Generate the design-time markup for the control when an error occurs. 
        Protected Overrides Function GetErrorDesignTimeHtml( _
            ByVal ex As Exception) As String 

            ' Write the error message text in red, bold. 
            Dim errorRendering As String = _
                "<span style=""font-weight:bold; color:Red; "">" & _
                ex.Message & "</span>" 

            Return CreatePlaceHolderDesignTimeHtml(errorRendering)

        End Function ' GetErrorDesignTimeHtml

        ' Generate the design-time markup for the control  
        ' when the template is empty. 
        Protected Overrides Function GetEmptyDesignTimeHtml() As String 

            ' Generate a design-time placeholder containing the names of all 
            ' the role groups. 
            Dim myLoginViewCtl As MyLoginView = CType(ViewControl, MyLoginView)
            Dim roleGroups As RoleGroupCollection = myLoginViewCtl.RoleGroups
            Dim RoleNames As String = Nothing 
            Dim rgX As Integer 

            ' If there are any role groups, form a string of their names. 
            If roleGroups.Count > 0 Then

                roleNames = "Role Groups: <br /> &nbsp;&nbsp;" & _

                For rgX = 1 To roleGroups.Count - 1
                    roleNames &= "<br /> &nbsp;&nbsp;" & _
                Next rgX
            End If 

            Return CreatePlaceHolderDesignTimeHtml(roleNames)

        End Function ' GetEmptyDesignTimeHtml

        ' Shadow control properties with design-time properties. 
        Protected Overrides Sub PreFilterProperties( _
            ByVal properties As IDictionary)

            ' Call the base method first. 

            ' Make the NamingContainer visible in the Properties grid. 
            Dim selectProp As PropertyDescriptor = _
                CType(properties("NamingContainer"), PropertyDescriptor)
            properties("NamingContainer") = _
                TypeDescriptor.CreateProperty(selectProp.ComponentType, _
                    selectProp, BrowsableAttribute.Yes)

        End Sub ' PreFilterProperties

        ' Generate the design-time markup. 
        Public Overrides Function GetDesignTimeHtml( _
            ByVal regions As DesignerRegionCollection) As String 

            ' Make the control more visible in the designer.   
            ' Enclose the markup in a table with an orange border.  
            Dim openTableMarkup As String = _
                "<table><tr><td style=""border:4 solid #FF7F00;"">" 
            Dim closeTableMarkup As String = "</td></tr></table>" 

            ' Call the base method to generate the markup. 
            Dim markup As String = MyBase.GetDesignTimeHtml(regions)

            Return openTableMarkup & markup & closeTableMarkup

        End Function ' GetDesignTimeHtml

        ' Generate the design time markup. 
        Public Overrides Sub Initialize(ByVal component As IComponent)

            ' Ensure that only a MyLoginView can be created in this designer.  
            If Not TypeOf component Is MyLoginView Then 
                Throw New ArgumentException()
            End If 

            ' Call the base method to generate the markup. 

        End Sub ' Initialize
    End Class ' MyLoginViewDesigner
End Namespace ' Examples.VB.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 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

Community Additions

© 2016 Microsoft