This documentation is archived and is not being maintained.

CustomValidator.ServerValidate Event

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 Web site.

Namespace:  System.Web.UI.MobileControls
Assembly:  System.Web.Mobile (in System.Web.Mobile.dll)

public event ServerValidateEventHandler ServerValidate
<asp:CustomValidator OnServerValidate="ServerValidateEventHandler" />

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="C#" 
    Inherits="System.Web.UI.MobileControls.MobilePage" %>
<%@ Register TagPrefix="mobile" 
    Assembly="System.Web.Mobile" %>

<script runat="server">
    // If the page validates, go to page 2
    protected void Submit_Click(Object sender, EventArgs e)
        if (Page.IsValid)
            ActiveForm = Form2;

    // Validate whether the number is even
    private void ServerValidate(object source, 
        ServerValidateEventArgs args)
        // Convert the text to a number
        int num;
        Int32.TryParse(numberBox.Text, out num);
        // Test for an even number
        if (num > 0)
            args.IsValid = ((num % 2) == 0);
            args.IsValid = false;

<html xmlns="" >
    <mobile:form id="Form1" runat="server">
        <mobile:Label ID="Label1" runat="server">
            Please enter an even number greater than zero.
        <mobile:TextBox ID="numberBox" Runat="server" 
            Numeric="true" MaxLength="2" />
        <mobile:CustomValidator ID="CustomValidator1" 
            OnServerValidate="ServerValidate" runat="server">
            Your number is not an even number.
        <mobile:Command ID="Command1" runat="server" 
    <mobile:Form id="Form2" runat="server">
        <mobile:Label ID="Label2" runat="server">
            Your number is an even number.

.NET Framework

Supported in: 4, 3.5, 3.0, 2.0, 1.1

Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.