Export (0) Print
Expand All
This topic has not yet been rated - Rate this topic

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)

public class BaseValidatorDesigner : PreviewControlDesigner
public class BaseValidatorDesigner extends PreviewControlDesigner
public class BaseValidatorDesigner extends PreviewControlDesigner

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.

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

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, 1.1, 1.0
Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft. All rights reserved.