BaseValidatorDesigner クラス
アセンブリ: System.Design (system.design.dll 内)


ビジュアル デザイナでソース ビューからデザイン ビューに切り替えると、BaseValidator 抽象クラスから派生したコントロールを記述するマークアップのソース コードが解析され、コントロールのデザイン時バージョンがデザイン サーフェイスに作成されます。元のソース ビューに切り替えると、デザイン時のコントロールがマークアップのソース コードに保持され、Web ページのマークアップに反映されます。BaseValidatorDesigner オブジェクトは、ビジュアル デザイナで BaseValidator クラスから派生したコントロールをデザイン時に使用できるようにします。
GetDesignTimeHtml メソッドは、関連付けられたコントロールのデザイン時表示に使用するマークアップを取得します。

CompareValidator クラスから SimpleCompareValidator コントロールを派生する例を次に示します。SimpleCompareValidator は CompareValidator のコピーです。この例では、さらに、BaseValidatorDesigner クラスから SimpleCompareValidatorDesigner クラスを派生し、DesignerAttribute 属性を使用して、SimpleCompareValidatorDesigner クラスを SimpleCompareValidator コントロールに関連付けています。
SimpleCompareValidatorDesigner は、GetDesignTimeHtml メソッドをオーバーライドして、SimpleCompareValidator コントロールの BorderStyle プロパティの値が NotSet フィールドまたは None フィールドである場合に実線の境界線をコントロールの周囲に描画します。
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

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


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 によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


- BaseValidatorDesigner クラスのページへのリンク