Validation By Control ASP.Net

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="Default" %>



    Default


    
    

                           runat="server" 
                   Text="The Following Field Must Be a Date and Earlier than Today">
        
                                      runat="server" 
                              ControlToValidate="TextBox2"
                              ErrorMessage="TextBox2 Must Be a Date and Earlier than Today" 
                              Operator="LessThan"
                              SetFocusOnError="True" 
                              Type="Date">*
        
         
        The Following Fields Must Contain a Early Date and a Later Date
        
        
        
                                      runat="server" 
                              ControlToCompare="TextBox6"
                              ControlToValidate="TextBox5" 
                              ErrorMessage="TextBox5 Must be Earlier Than TextBox6"
                              Operator="GreaterThan" 
                              Type="Date">*
                            runat="server" 
                    OnClick="Button1_Click" 
                    Text="Submit" />
                            runat="server" 
                    CausesValidation="False" 
                    Text="Cancel - Will Not Validate!" />
                            runat="server" 
                    Text="Validate DropDownList1 Only" 
                    ValidationGroup="DDL" />
        
                                       runat="server" 
                               ShowMessageBox="True"
                               ValidationGroup="DDL" />
    

    


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 Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
    this.CompareValidator1.ValueToCompare = DateTime.Today.ToShortDateString();
    }
  protected void Button1_Click(object sender, EventArgs e)
  {
    this.Validate(string.Empty);
    if (this.IsValid==false)
    {
      // Do something...
    }
  }
}