RangeValidator.EvaluateIsValid Method ()
.NET Framework (current version)
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.
Assembly: System.Web (in System.Web.dll)
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.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>
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
.NET Framework
Available since 1.1
Available since 1.1
Show: