Freigeben über


CompareValidator.ControlPropertiesValid-Methode

Diese Methode unterstützt die .NET Framework-Infrastruktur und ist nicht für die direkte Verwendung in Code bestimmt.

Überprüft die Eigenschaften des Steuerelements auf gültige Werte.

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

Syntax

'Declaration
Protected Overrides Function ControlPropertiesValid As Boolean
'Usage
Dim returnValue As Boolean

returnValue = Me.ControlPropertiesValid
protected override bool ControlPropertiesValid ()
protected:
virtual bool ControlPropertiesValid () override
protected boolean ControlPropertiesValid ()
protected override function ControlPropertiesValid () : boolean

Rückgabewert

true, wenn die Steuerelementeigenschaften gültig sind, andernfalls false.

Beispiel

Das folgende Codebeispiel veranschaulicht das Überschreiben der ControlPropertiesValid-Methode in einem benutzerdefinierten Serversteuerelement, sodass es immer den Wert der sichtbaren Eigenschaft zurückgibt, solange sich die ControlToCompare-Eigenschaft des CompareValidator-Steuerelements auf der Seite befindet und Validierungseigenschaften enthält.

<%@ Register TagPrefix="aspSample" Namespace="Samples.AspNet.VB.Controls" Assembly="Samples.AspNet.VB" %>
<%@ Page language="VB" %>
<HTML>
  <HEAD>
    <title>Custom CompareValidator - ControlPropertiesValid - VB.NET Example</title>
  </HEAD>
  <body>
    <form id="Form1" method="post" runat="server">
      <h3>Custom CompareValidator - ControlPropertiesValid - C# Example</h3>
            <asp:TextBox id="TextBox1" runat="server">123</asp:TextBox><BR>
            <aspSample:CustomCompareValidatorControlPropertiesValid
             id="CompareValidator1" runat="server" Display="Dynamic"
             ErrorMessage="The value of TextBox1 must be '456'."
             ControlToValidate="TextBox1" ValueToCompare="456" /><br>
             <asp:Button id="Button1" runat="server" Text="Button" />
    </form>
  </body>
</HTML>

...
Imports System.Web
Imports System.Security.Permissions

Namespace Samples.AspNet.VB.Controls
    <AspNetHostingPermission(SecurityAction.Demand, Level:=AspNetHostingPermissionLevel.Minimal)> _
    Public NotInheritable Class CustomCompareValidatorControlPropertiesValid
        Inherits System.Web.UI.WebControls.CompareValidator

        Protected Overrides Function ControlPropertiesValid() As Boolean

            ' Determine whether the ControlToValidate is on the page and contains a validation properties. 
            MyBase.CheckControlValidationProperty(Me.ControlToValidate, "ControlToValidate")

            ' If the control is visible, then control is valid and ready for validation.
            Dim control As System.Web.UI.Control = Me.FindControl(Me.ControlToValidate)
            If control.Visible = True Then
                Return True
            Else
                Return False
            End If
        End Function
    End Class
End Namespace
<%@ Register TagPrefix="aspSample" Namespace="Samples.AspNet.CS.Controls" Assembly="Samples.AspNet.CS" %>
<%@ Page language="c#" %>
<HTML>
  <HEAD>
    <title>Custom CompareValidator - ControlPropertiesValid - C# Example</title>
    <script runat="server">
      void Page_Load(Object sender, EventArgs e)
      {
        // Run the Page Validate method in order to force
        // the CompareValidate to show it's error message.
        Page.Validate();
      }
    </script>
  </HEAD>
  <body>
    <form id="Form1" method="post" runat="server">
      <h3>Custom CompareValidator - ControlPropertiesValid - C# Example</h3>

      <asp:TextBox id="TextBox1" runat="server">123</asp:TextBox><BR>

      <aspSample:CustomCompareValidatorControlPropertiesValid
        id="CompareValidator1"
        runat="server"
        Display="Dynamic"
        ErrorMessage="The value of TextBox1 must be '456'."
        ControlToValidate="TextBox1"
        ValueToCompare="456" /><br>

      <asp:Button id="Button1" runat="server" Text="Button" />

    </form>
  </body>
</HTML>

...
using System.Web;
using System.Security.Permissions;

namespace Samples.AspNet.CS.Controls
{
    [AspNetHostingPermission(SecurityAction.Demand, Level = AspNetHostingPermissionLevel.Minimal)]
    public sealed class CustomCompareValidatorControlPropertiesValid : System.Web.UI.WebControls.CompareValidator
    {
        protected override bool ControlPropertiesValid()
        {
            // Determine whether the ControlToValidate is on the page and contains a validation properties. 
            base.CheckControlValidationProperty(this.ControlToValidate, "ControlToValidate");

            // If the control is visible, then control is valid and is ready for validation.
            System.Web.UI.Control control = this.FindControl(this.ControlToValidate);
            return control.Visible;
        }
    }
}
<%@ Register TagPrefix="aspSample" Namespace="Samples.AspNet.JSL.Controls" Assembly="Samples.AspNet.JSL" %>
<%@ Page language="VJ#" %>
<HTML>
  <HEAD>
    <title>Custom CompareValidator - ControlPropertiesValid - VJ# Example</title>
    <script runat="server">
    void Page_Load(Object sender, EventArgs e)
    {
        // Run the Page Validate method in order to force
        // the CompareValidate to show it's error message.
        get_Page().Validate();
    } //Page_Load
    </script>
  </HEAD>
  <body>
    <form id="Form1" method="post" runat="server">
      <h3>Custom CompareValidator - ControlPropertiesValid - VJ# Example</h3>

      <asp:TextBox id="TextBox1" runat="server" Text="123"></asp:TextBox><BR>

      <aspSample:CustomCompareValidatorControlPropertiesValid
        id="CompareValidator1"
        runat="server"
        Display="Dynamic"
        ErrorMessage="The value of TextBox1 must be '456'."
        ControlToValidate="TextBox1"
        ValueToCompare="456" /><br>

      <asp:Button id="Button1" runat="server" Text="Button" />

    </form>
  </body>
</HTML>

...
package Samples.AspNet.JSL.Controls;

public class CustomCompareValidatorControlPropertiesValid
    extends System.Web.UI.WebControls.CompareValidator
{
    protected boolean ControlPropertiesValid()
    {
        // Determine whether the ControlToValidate is on the page 
        // and contains a validation properties. 
        super.CheckControlValidationProperty(this.get_ControlToValidate(),
            "ControlToValidate");
        // If the control is visible, then control is valid and is ready 
        // for validation.
        System.Web.UI.Control control = 
            this.FindControl(this.get_ControlToValidate());
        return control.get_Visible();
    } //ControlPropertiesValid
} //CustomCompareValidatorControlPropertiesValid

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

CompareValidator-Klasse
CompareValidator-Member
System.Web.UI.WebControls-Namespace