Freigeben über


BaseValidatorDesigner-Klasse

Stellt Entwurfszeitunterstützung in einem visuellen Designer für Webserversteuerelemente bereit, die von der BaseValidator-Klasse abgeleitet sind.

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

Syntax

'Declaration
Public Class BaseValidatorDesigner
    Inherits PreviewControlDesigner
'Usage
Dim instance As BaseValidatorDesigner
public class BaseValidatorDesigner : PreviewControlDesigner
public ref class BaseValidatorDesigner : public PreviewControlDesigner
public class BaseValidatorDesigner extends PreviewControlDesigner
public class BaseValidatorDesigner extends PreviewControlDesigner

Hinweise

Wenn Sie in einem visuellen Designer von der Quellansicht zur Entwurfsansicht wechseln, wird der Markupquellcode analysiert, der ein von der abstrakten BaseValidator-Klasse abgeleitetes Steuerelement beschreibt, und auf der Entwurfsoberfläche wird eine Entwurfszeitversion des Steuerelements erstellt. Wenn Sie zurück zur Quellansicht wechseln, wird das Entwurfszeit-Steuerelement im Markupquellcode beibehalten und in das Markup für die Webseite eingearbeitet. Die BaseValidatorDesigner-Objekte bieten in einem visuellen Designer Entwurfszeitunterstützung für Steuerelemente, die von der BaseValidator-Klasse abgeleitet sind.

Die GetDesignTimeHtml-Methode ruft das Markup ab, das zum Rendern des zugeordneten Steuerelements zur Entwurfszeit verwendet wird.

Beispiel

Im folgenden Beispiel wird das SimpleCompareValidator-Steuerelement von der CompareValidator-Klasse abgeleitet. SimpleCompareValidator ist eine Kopie von CompareValidator. Außerdem wird der SimpleCompareValidatorDesigner von der BaseValidatorDesigner-Klasse abgeleitet, und der SimpleCompareValidatorDesigner-Klasse wird mithilfe des DesignerAttribute-Attributs das SimpleCompareValidator-Steuerelement zugeordnet.

Der SimpleCompareValidatorDesigner überschreibt die GetDesignTimeHtml-Methode, um zur Entwurfszeit einen durchgezogenen Rahmen um das SimpleCompareValidator-Steuerelement zu ziehen, wenn der Wert der BorderStyle-Eigenschaft des Steuerelements das NotSet-Feld oder das None-Feld ist.

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
using System;
using System.Web;
using System.Web.UI.WebControls;
using System.Web.UI.Design.WebControls;
using System.ComponentModel;
using System.Security.Permissions;

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

    // Derive a designer that inherits from the BaseValidatorDesigner.
    public class SimpleCompareValidatorDesigner : 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 override string GetDesignTimeHtml()
        {
            // Get a reference to the control or a copy of the control.
            SimpleCompareValidator myCV = (SimpleCompareValidator)ViewControl;
            string markup = null;

            // Check if the border style should be changed.
            if (myCV.BorderStyle == BorderStyle.NotSet ||
                myCV.BorderStyle == BorderStyle.None)
            {
                // Save the current property setting.
                BorderStyle oldBorderStyle = 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 = base.GetDesignTimeHtml();
                }
                catch (Exception ex)
                {
                    markup = GetErrorDesignTimeHtml(ex);
                }
                finally
                {
                    // Restore the property to its original setting.
                    myCV.BorderStyle = oldBorderStyle;
                }
            }
            else
                // Call the base method to generate the markup.
                markup = base.GetDesignTimeHtml();

            return markup;

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

Vererbungshierarchie

System.Object
   System.ComponentModel.Design.ComponentDesigner
     System.Web.UI.Design.HtmlControlDesigner
       System.Web.UI.Design.ControlDesigner
         System.Web.UI.Design.WebControls.PreviewControlDesigner
          System.Web.UI.Design.WebControls.BaseValidatorDesigner

Threadsicherheit

Alle öffentlichen statischen (Shared in Visual Basic) Member dieses Typs sind threadsicher. Bei Instanzmembern ist die Threadsicherheit nicht gewährleistet.

Plattformen

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

.NET Framework unterstützt nicht alle Versionen sämtlicher Plattformen. Eine Liste der unterstützten Versionen finden Sie unter Systemanforderungen.

Versionsinformationen

.NET Framework

Unterstützt in: 2.0, 1.1, 1.0

Siehe auch

Referenz

BaseValidatorDesigner-Member
System.Web.UI.Design.WebControls-Namespace
BaseValidator
PreviewControlDesigner
ControlDesigner-Klasse

Weitere Ressourcen

Übersicht über ASP.NET-Steuerelement-Designer
Exemplarische Vorgehensweise: Erstellen eines einfachen Steuerelement-Designers für ein Webserver-Steuerelement