Freigeben über


RangeValidator.EvaluateIsValid-Methode

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

Bestimmt, ob der Inhalt des Eingabesteuerelements gültig ist.

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

Syntax

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

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

Rückgabewert

true, wenn das Steuerelement gültig ist, andernfalls false.

Beispiel

Im folgenden Codebeispiel wird veranschaulicht, wie die EvaluateIsValid-Methode in einem Serversteuerelement überschrieben wird. Dabei wird stets überprüft, ob der Wert vorhanden ist und sich zwischen dem Höchst- und dem Mindestwert befindet, die für den RangeValidator angegeben sind.

<%@ Register TagPrefix="aspSample" Namespace="Samples.AspNet.VB.Controls" Assembly="Samples.AspNet.VB" %>
<%@ Page Language="VB" AutoEventWireup="True" %>
<HTML>
    <HEAD>
        <title>Custom RangeValidator - EvaluateIsValid - VB.NET Example</title>
        <script runat="server">
            Sub ButtonClick(sender As Object, e As EventArgs)
                If Page.IsValid Then
                    Label1.Text="Page is valid."
                Else
                    Label1.Text="Page is not valid!"
                End If
            End Sub
        </script>
    </HEAD>
    <body>
        <form id="Form1" method="post" runat="server">
            <h3>Custom RangeValidator - EvaluateIsValid - VB.NET Example</h3>

            Enter a number from 1 to 10:<br>
            <asp:TextBox id="TextBox1" Runat="server" />
            
            <aspSample:CustomRangeValidatorEvaluateIsValid id="RangeValidator1" runat="server" 
             ControlToValidate="TextBox1" MinimumValue="1" MaximumValue="10" Type="Integer" 
             EnableClientScript="false" Text="The value must be from 1 to 10!" /><br>
             <br>
             
            <asp:Button id="Button1" Text="Submit" OnClick="ButtonClick" runat="server" /><br>
             <br>
             
            <asp:Label id="Label1" runat="server"/>
        </form>
    </body>
</HTML>

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

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

        Protected Overrides Function EvaluateIsValid() As Boolean

            ' Get the value of the control to validate.
            Dim controlValue As String = GetControlValidationValue(ControlToValidate)

            ' If no value was entered, show the validation error by returning false.
            If controlValue.Trim().Length = 0 Then
                Return False
            End If

            ' Compare the ControlToValidate's value against the minimum and maximum values.
            Return Compare(controlValue, Me.MinimumValue, System.Web.UI.WebControls.ValidationCompareOperator.GreaterThanEqual, Me.Type) AndAlso _
                   Compare(controlValue, Me.MaximumValue, System.Web.UI.WebControls.ValidationCompareOperator.LessThanEqual, Me.Type)
        End Function
    End Class
End Namespace
<%@ Register TagPrefix="aspSample" Namespace="Samples.AspNet.CS.Controls" Assembly="Samples.AspNet.CS" %>
<%@ Page Language="C#" AutoEventWireup="True" %>
<HTML>
  <HEAD>
    <title>Custom RangeValidator - EvaluateIsValid - C# Example</title>
    <script runat="server">
      void ButtonClick(Object sender, EventArgs e)
      {
        if (Page.IsValid)
        {
          Label1.Text="Page is valid.";
        }
        else
        {
          Label1.Text="Page is not valid!!";
        }
      }
    </script>
  </HEAD>
  <body>
    <form id="Form1" method="post" runat="server">
      <h3>Custom RangeValidator - EvaluateIsValid - C# Example</h3>

      Enter a number from 1 to 10:<br>
      <asp:TextBox id="TextBox1" Runat="server" />

      <aspSample:CustomRangeValidatorEvaluateIsValid 
        id="RangeValidator1" 
        runat="server" 
        ControlToValidate="TextBox1" 
        MinimumValue="1" 
        MaximumValue="10" 
        Type="Integer" 
        EnableClientScript="false" 
        Text="The value must be from 1 to 10!" />
        
      <br>
      <br>
      <asp:Button id="Button1" Text="Submit" OnClick="ButtonClick" runat="server" /><br>
      <br>

      <asp:Label id="Label1" runat="server" />
    </form>
  </body>
</HTML>

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

namespace Samples.AspNet.CS.Controls
{
  [AspNetHostingPermission(SecurityAction.Demand, Level=AspNetHostingPermissionLevel.Minimal)]
  public sealed class CustomRangeValidatorEvaluateIsValid : System.Web.UI.WebControls.RangeValidator
  {
    protected override bool EvaluateIsValid()
    {
      // Get the value of the control to validate.
      string controlValue = GetControlValidationValue(ControlToValidate);

      // If no value was entered, show the validation error by returning false.
      if (controlValue.Trim().Length == 0) 
      {
        return false;
      }

      // Compare the ControlToValidate's value against the minimum and maximum values.
      return(Compare(controlValue, this.MinimumValue, System.Web.UI.WebControls.ValidationCompareOperator.GreaterThanEqual, this.Type) &&
        Compare(controlValue, this.MaximumValue, System.Web.UI.WebControls.ValidationCompareOperator.LessThanEqual, this.Type));
    }            
  }
}
<%@ Register TagPrefix="aspSample" Namespace="Samples.AspNet.JSL.Controls" Assembly="Samples.AspNet.JSL" %>
<%@ Page Language="VJ#" AutoEventWireup="True" %>
<HTML>
  <HEAD>
    <title>Custom RangeValidator - EvaluateIsValid - VJ# Example</title>
    <script runat="server">
        void ButtonClick(Object sender, EventArgs e)
        {
            if (get_Page().get_IsValid()) {
                Label1.set_Text("Page is valid.");
            }
            else {
                Label1.set_Text("Page is not valid!!");
            }
        } //ButtonClick
    </script>
  </HEAD>
  <body>
    <form id="Form1" method="post" runat="server">
      <h3>Custom RangeValidator - EvaluateIsValid - VJ# Example</h3>

      Enter a number from 1 to 10:<br>
      <asp:TextBox id="TextBox1" Runat="server" />

      <aspSample:CustomRangeValidatorEvaluateIsValid 
        id="RangeValidator1" 
        runat="server" 
        ControlToValidate="TextBox1" 
        MinimumValue="1" 
        MaximumValue="10" 
        Type="Integer" 
        EnableClientScript="false" 
        Text="The value must be from 1 to 10!" />
        
      <br>
      <br>
      <asp:Button id="Button1" Text="Submit" OnClick="ButtonClick" runat="server" /><br>
      <br>

      <asp:Label id="Label1" runat="server" />
    </form>
  </body>
</HTML>

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

public class CustomRangeValidatorEvaluateIsValid
    extends System.Web.UI.WebControls.RangeValidator
{
    protected boolean EvaluateIsValid()
    {
        // Get the value of the control to validate.
        String controlValue = GetControlValidationValue(get_ControlToValidate());
        // If no value was entered, show the validation error by returning false.
        if (controlValue.Trim().get_Length() == 0) {
            return false;
        }
        // Compare the ControlToValidate's value against the 
        // minimum and maximum values.
        return Compare(controlValue, this.get_MinimumValue(), 
            System.Web.UI.WebControls.ValidationCompareOperator.
            GreaterThanEqual,this.get_Type()) && Compare(controlValue, 
            this.get_MaximumValue(),System.Web.UI.WebControls.
            ValidationCompareOperator.LessThanEqual,this.get_Type());
    } //EvaluateIsValid
} //CustomRangeValidatorEvaluateIsValid

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

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