다음을 통해 공유


RangeValidator.EvaluateIsValid 메서드

정의

입력 컨트롤의 내용이 유효한지 여부를 확인합니다.

protected:
 override bool EvaluateIsValid();
protected override bool EvaluateIsValid ();
override this.EvaluateIsValid : unit -> bool
Protected Overrides Function EvaluateIsValid () As Boolean

반환

컨트롤이 유효하면 true이고, 그렇지 않으면 false입니다.

예제

다음 코드 예제에서는 재정의 하는 방법에 설명 합니다 EvaluateIsValid 값이 있고 내 최대값 및 최소값에 대 한 지정 된 항상 유효한 지 확인 하도록 컨트롤을 사용자 지정 서버에서 메서드를 RangeValidator입니다.

<%@ Register TagPrefix="aspSample" Namespace="Samples.AspNet.CS.Controls" Assembly="Samples.AspNet.CS" %>
<%@ Page Language="C#" AutoEventWireup="True" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
  <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>
<%@ Register TagPrefix="aspSample" Namespace="Samples.AspNet.VB.Controls" Assembly="Samples.AspNet.VB" %>
<%@ Page Language="VB" AutoEventWireup="True" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
    <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>
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));
    }            
  }
}
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

적용 대상