Compare Validator Disable Submit when validtion failed

Hi Dudes,

Little info about compare validator . We need to set


ValidationGroup=”SetSameNameAsLike in SubmitButton”

Operator –> If we set Greater than equal means it will show error message when we enter lesser date

If u need to compare with Current Date means need to set ValueToCompare  property in page_load. Like a mentioned follow….

Aspx Side :

<asp:TextBox ID=”txtDueDate” Cs  ReadOnly=”true” runat=”server” />

<asp:CompareValidator ID=”cmpVal1″ ControlToValidate=”txtDueDate” Display=”Dynamic”  ValidationGroup=”SaveGroup” Type=”Date” Operator=”GreaterThanEqual”   SetFocusOnError=”true” BorderColor=”Red”  ErrorMessage=”Cannot be lesser than today”
ToolTip=”Date cannot be lesser than today” runat=”server”></asp:CompareValidator>

<asp:Button ID=”btnSave”   ValidationGroup=”SaveGroup” runat=”server”      Text=”Save” CssClass=”button” OnClientClick=”return validateAnalysisElements()”                                                        OnClick=”btnSave_Click” />

Script :

<script type=”text/javascript”>
function validateAnalysisElements() {
            if (Page_IsValid) {
                return true;
            else {
                return false;


In Page_Load  We need to set Current date to the compare validator . Then it can validate while compare

cmpVal1.ValueToCompare = DateTime.Now.ToShortDateString();



Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s