This documentation is archived and is not being maintained.

BaseValidatorDesigner Class

Provides design-time support in a visual designer for Web server controls that are derived from the BaseValidator class.

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

'Declaration
<SupportsPreviewControlAttribute(True)> _
<SecurityPermissionAttribute(SecurityAction.Demand, Flags := SecurityPermissionFlag.UnmanagedCode)> _
Public Class BaseValidatorDesigner _
	Inherits PreviewControlDesigner
'Usage
Dim instance As BaseValidatorDesigner

In a visual designer, when you switch from Source to Design view, the markup source code that describes a control that is derived from the BaseValidator abstract class 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 markup source code and edited into the markup for the Web page. The BaseValidatorDesigner objects provide design-time support for controls that are derived from the BaseValidator class in a visual designer.

The GetDesignTimeHtml method gets the markup that is used to render the associated control at design time.

The following example derives the SimpleCompareValidator control from the CompareValidator class. SimpleCompareValidator is a copy of the CompareValidator. The example also derives the designer SimpleCompareValidatorDesigner from the BaseValidatorDesigner class and uses the DesignerAttribute attribute to associate the SimpleCompareValidatorDesigner class with the SimpleCompareValidator control.

SimpleCompareValidatorDesigner overrides the GetDesignTimeHtml method to draw a solid border around the SimpleCompareValidator control at design time if the value of the BorderStyle property of the control is the NotSet or None field.

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

Namespace Examples.VB.WebControls.Design

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

    ' Derive a designer that inherits from the BaseValidatorDesigner. 
    Public Class SimpleCompareValidatorDesigner
        Inherits BaseValidatorDesigner

        ' Make the full extent of the control more visible in the designer. 
        ' If the border style is None or NotSet, change the border to a  
        ' solid line.  
        Public Overrides Function GetDesignTimeHtml() As String 

            ' Get a reference to the control or a copy of the control. 
            Dim myCV As SimpleCompareValidator = _
                CType(ViewControl, SimpleCompareValidator)
            Dim markup As String 

            ' Check if the border style should be changed. 
            If (myCV.BorderStyle = BorderStyle.NotSet Or _
                myCV.BorderStyle = BorderStyle.None) Then 

                ' Save the current property setting. 
                Dim oldBorderStyle As BorderStyle = myCV.BorderStyle

                ' Set the design-time property and catch any exceptions. 
                Try
                    myCV.BorderStyle = BorderStyle.Solid

                    ' Call the base method to generate the markup.
                    markup = MyBase.GetDesignTimeHtml()

                Catch ex As Exception
                    markup = GetErrorDesignTimeHtml(ex)

                Finally 
                    ' Restore the property to its original setting.
                    myCV.BorderStyle = oldBorderStyle
                End Try 

            Else 
                ' Call the base method to generate the markup.
                markup = MyBase.GetDesignTimeHtml()
            End If 

            Return markup
        End Function 
    End Class ' SimpleCompareValidatorDesigner
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, 1.1, 1.0
Show: