CustomValidator.ServerValidate Event
.NET Framework (current version)
Occurs when the CustomValidator validates the value of the ControlToValidate property. This API is obsolete. For information about how to develop ASP.NET mobile applications, see the www.asp.net/mobile Web site.
Assembly: System.Web.Mobile (in System.Web.Mobile.dll)
If a method is registered with this event, it is called with the value of the ControlToValidate property. Validation succeeds only if this event handler returns true.
The following example demonstrates how to trap the ServerValidate event to add logic to validate the page.
<%@ Page Language="VB" Inherits="System.Web.UI.MobileControls.MobilePage" %> <%@ Register TagPrefix="mobile" Namespace="System.Web.UI.MobileControls" Assembly="System.Web.Mobile" %> <script runat="server"> ' If the page validates, go to page 2 Protected Sub Submit_Click(ByVal sender As Object, ByVal e As EventArgs) If (Page.IsValid) Then ActiveForm = Form2 End If End Sub ' Validate whether the number is even Private Sub ServerValidate(ByVal source As Object, _ ByVal args As ServerValidateEventArgs) ' Convert the text to a number Dim num As Integer Integer.TryParse(numberBox.Text, num) ' Test for an even number If (num > 0) Then args.IsValid = ((num Mod 2) = 0) Else args.IsValid = False End If End Sub </script> <html xmlns="http://www.w3.org/1999/xhtml" > <body> <mobile:form id="Form1" runat="server"> <mobile:Label ID="Label1" runat="server"> Please enter an even number greater than zero. </mobile:Label> <mobile:TextBox ID="numberBox" Runat="server" Numeric="true" MaxLength="2" /> <mobile:CustomValidator ID="CustomValidator1" ControlToValidate="numberBox" OnServerValidate="ServerValidate" runat="server"> Your number is not an even number. </mobile:CustomValidator> <mobile:Command ID="Command1" runat="server" OnClick="Submit_Click"> Submit </mobile:Command> </mobile:form> <mobile:Form id="Form2" runat="server"> <mobile:Label ID="Label2" runat="server"> Your number is an even number. </mobile:Label> </mobile:Form> </body> </html>
.NET Framework
Available since 1.1
Available since 1.1
CustomValidator Class
System.Web.UI.MobileControls Namespace
Introduction to the CustomValidator Control
Adding and Configuring a CustomValidator Control
Show: