Wrox Programmer Forums
|
ASP.NET 1.0 and 1.1 Basics ASP.NET discussion for users new to coding in ASP.NET 1.0 or 1.1. NOT for the older "classic" ASP 3 or the newer ASP.NET 2.0.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 1.0 and 1.1 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old August 27th, 2003, 09:55 AM
Registered User
 
Join Date: Jun 2003
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default CompareValidator

Ok, forgive me if this is something basic. I have the stuff below. It works. What I don't like is that if I enter a value that matches both conditions it displays both error messages. Personally, in that situation, I would rather it just display the first one. How could I go about making that happen?

Thanks,

Jerry

<%-- This stuff is displayed for user interaction --%>
Go to page: <asp:TextBox Runat="server" name="txtPage" ID="txtPage" Width="50" /> <asp:Button Runat=server ID="btnGo" Name="btnGo" Text="Go" /> Page <asp:Label ID="lblCurrentPage" Runat=server /> of <asp:Label ID="lblTotal" Runat=server /> <br>

<%-- Here are the validators --%>
<asp:CompareValidator runat="server" id="compPrimeNumber"
    Operator="DataTypeCheck" Type="Integer"
    Display="Dynamic" ControlToValidate="txtPage"
    ErrorMessage = "You must enter an integer value." />

<asp:CompareValidator runat="server" id="compPrimeNumberPositive"
    Operator="GreaterThan" Type="Integer"
    Display="Dynamic" ValueToCompare="0"
    ControlToValidate="txtPage"
    ErrorMessage = "You must enter a value greater than zero." />
 
Old August 27th, 2003, 11:23 AM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

If this is all happening on the server side, you should be able to disable the second validator if the first is not valid.

In your page_load() do something like this:
Code:
compPrimeNumberPositive.Enabled = compPrimeNumber.IsValid





Similar Threads
Thread Thread Starter Forum Replies Last Post
Disabling automatic validation: comparevalidator? lancer ASP.NET 2.0 Basics 0 June 8th, 2006 01:28 PM
CompareValidator for Dates kapi.goel C# 0 April 18th, 2006 05:42 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.