<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="UsingCustomValidator" %>
Using a CustomValidator
File: Default.aspx.cs
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
public partial class UsingCustomValidator : System.Web.UI.Page
{
protected void custDate_ServerValidate(object source, ServerValidateEventArgs args)
{
string sEnteredDate = args.Value;
DateTime dt;
bool convertSuccessful = DateTime.TryParse(sEnteredDate, out dt);
if (convertSuccessful && dt >= DateTime.Today)
args.IsValid = true;
else
args.IsValid = false;
}
protected void OrFieldValidator_ServerValidate(object source, ServerValidateEventArgs args)
{
if (txtUser.Text.Length <= 0 && txtEmail.Text.Length <= 0)
args.IsValid = false;
else
args.IsValid = true;
}
}