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 Page_Load(object sender, EventArgs e)
   {
      // get the client script manager for the page
      ClientScriptManager csm = Page.ClientScript;
      // get the type for the page
      Type pageType = this.GetType();
      // only register script block if it hasn't already been registered
      if ( !csm.IsClientScriptBlockRegistered(pageType,"validateOr") )
      {
         // build the javascript string
         string strJavascript = BuildJavascript();
         // register the javascript block
         csm.RegisterClientScriptBlock(pageType, "validateOr", strJavascript);
      }
   }

   private string BuildJavascript()
   {
      string s = "function validateOrFields(source, args) { ";
      s += "var sUser = document.form1.<%= txtUser.ClientID %>.value; ";
      s += "var sEmail = document.form1.<%= txtEmail.ClientID %>.value; ";
      s += " if (sUser == '' && sEmail == '') {";
      s += " args.IsValid = false; }";
      s += " else { args.IsValid = true; } ";
      s += " return;   }  }";
      return s;
   }
    * */

   protected void custDate_ServerValidate(object source, ServerValidateEventArgs args)
   {
      // first try converting user input into a valid date
      string sEnteredDate = args.Value;
      DateTime dt;
      bool convertSuccessful = DateTime.TryParse(sEnteredDate, out dt);
      // if conversion was successful, check if it is in the future
      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;
   }
}
