EvaluateIsValid Method
Collapse the table of content
Expand the table of content

RangeValidator.EvaluateIsValid Method ()


This API supports the product infrastructure and is not intended to be used directly from your code.

Determines whether the content in the input control is valid.

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

protected override bool EvaluateIsValid()

Return Value

Type: System.Boolean

true if the control is valid; otherwise, false.

The following code example demonstrates how to override the EvaluateIsValid method in a custom server control so that it always validates that the value exists and is within the maximum and minimum values specified for the 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"
<html xmlns="http://www.w3.org/1999/xhtml" >
    <title>Custom RangeValidator - EvaluateIsValid - C# Example</title>
    <script runat="server">
      void ButtonClick(Object sender, EventArgs e)
        if (Page.IsValid)
          Label1.Text="Page is valid.";
          Label1.Text="Page is not valid!!";
    <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" />

        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" />
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));

.NET Framework
Available since 1.1
Return to top
© 2016 Microsoft