CompareValidator.EvaluateIsValid-Methode
Diese Methode unterstützt die .NET Framework-Infrastruktur und ist nicht für die direkte Verwendung in Code bestimmt.
Diese Methode enthält beim Überschreiben in einer abgeleiteten Klasse den Code, der bestimmt, ob der Wert im Eingabesteuerelement 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 der Wert im Eingabesteuerelement gültig ist, andernfalls false.
Beispiel
Im folgenden Codebeispiel wird veranschaulicht, wie die EvaluateIsValid-Methode in einem benutzerdefinierten Serversteuerelement überschrieben wird, sodass sie immer true zurückgibt, wenn die Werte der zwei angegebenen Steuerelemente gleich sind. Andernfalls gibt sie false zurück.
<%@ Register TagPrefix="aspSample" Namespace="Samples.AspNet.VB.Controls" Assembly="Samples.AspNet.VB" %>
<%@ Page language="VB" %>
<HTML>
<HEAD>
<title>Custom CompareValidator - EvaluateIsValid - VB.NET Example</title>
</HEAD>
<body>
<form id="Form1" method="post" runat="server">
<h3>Custom CompareValidator - EvaluateIsValid - C# Example</h3>
<asp:TextBox id="TextBox1" runat="server">123</asp:TextBox><BR>
<asp:TextBox id="TextBox2" runat="server">123</asp:TextBox>
<aspSample:CustomCompareValidatorEvaluateIsValid
id="CompareValidator1" runat="server"
ErrorMessage="Value in TextBox2 does not match value in TextBox1."
Display="Dynamic" ControlToCompare="TextBox2" ControlToValidate="TextBox1" /><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 CustomCompareValidatorEvaluateIsValid
Inherits System.Web.UI.WebControls.CompareValidator
Protected Overrides Function EvaluateIsValid() As Boolean
' Get the values from the two controls
Dim controlToValidateValue As String = Me.GetControlValidationValue(Me.ControlToValidate)
Dim controlToCompareValue As String = Me.GetControlValidationValue(Me.ControlToCompare)
' If the values are the same, return true, else return false.
If (System.String.Compare(controlToValidateValue, 0, controlToCompareValue, 0, controlToCompareValue.Length, False, System.Globalization.CultureInfo.InvariantCulture) = 0) Then
Return True
Else
Return False
End If
End Function
End Class
End Namespace
<%@ Register TagPrefix="aspSample" Namespace="Samples.AspNet" Assembly="Samples.AspNet.CS" %>
<%@ Page language="c#" %>
<HTML>
<HEAD>
<title>Custom CompareValidator - EvaluateIsValid - 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 - EvaluateIsValid - C# Example</h3>
<asp:TextBox id="TextBox1" runat="server">123</asp:TextBox><BR>
<asp:TextBox id="TextBox2" runat="server">123</asp:TextBox>
<aspSample:CustomCompareValidatorEvaluateIsValid
id="CompareValidator1"
runat="server"
ErrorMessage="Value in TextBox2 does not match value in TextBox1."
Display="Dynamic"
ControlToCompare="TextBox2"
ControlToValidate="TextBox1" /><br>
<asp:Button id="Button1" runat="server" Text="Button" />
</form>
</body>
</HTML>
...
using System.Web;
using System.Security.Permissions;
namespace Samples.AspNet
{
[AspNetHostingPermission(SecurityAction.Demand, Level = AspNetHostingPermissionLevel.Minimal)]
public sealed class CustomCompareValidatorEvaluateIsValid : System.Web.UI.WebControls.CompareValidator
{
protected override bool EvaluateIsValid()
{
// Get the values from the two controls
string controlToValidateValue = this.GetControlValidationValue(this.ControlToValidate);
string controlToCompareValue = this.GetControlValidationValue(this.ControlToCompare);
// If the values are the same, return true, else return false.
if (System.String.Compare(controlToValidateValue, 0, controlToCompareValue, 0, controlToCompareValue.Length, false, System.Globalization.CultureInfo.InvariantCulture) == 0)
{
return true;
}
else
{
return false;
}
}
}
}
<%@ Register TagPrefix="aspSample" Namespace="Samples.AspNet" Assembly="Samples.AspNet.JSL" %>
<%@ Page language="VJ#" %>
<HTML>
<HEAD>
<title>Custom CompareValidator - EvaluateIsValid - 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 - EvaluateIsValid - VJ# Example</h3>
<asp:TextBox id="TextBox1" runat="server" Text="123"></asp:TextBox><BR>
<asp:TextBox id="TextBox2" runat="server" Text="123"></asp:TextBox>
<aspSample:CustomCompareValidatorEvaluateIsValid
id="CompareValidator1"
runat="server"
ErrorMessage="Value in TextBox2 does not match value in TextBox1."
Display="Dynamic"
ControlToCompare="TextBox2"
ControlToValidate="TextBox1" /><br>
<asp:Button id="Button1" runat="server" Text="Button" />
</form>
</body>
</HTML>
...
package Samples.AspNet;
public class CustomCompareValidatorEvaluateIsValid
extends System.Web.UI.WebControls.CompareValidator
{
protected boolean EvaluateIsValid()
{
// Get the values from the two controls
String controlToValidateValue = this.GetControlValidationValue(
this.get_ControlToValidate());
String controlToCompareValue = this.GetControlValidationValue(
this.get_ControlToCompare());
// If the values are the same, return true, else return false.
if (System.String.Compare(controlToValidateValue, 0,
controlToCompareValue, 0, controlToCompareValue.get_Length(),
false, System.Globalization.CultureInfo.get_InvariantCulture()) ==
0) {
return true;
}
else {
return false;
}
} //EvaluateIsValid
} //CustomCompareValidatorEvaluateIsValid
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