Click here to Skip to main content
15,892,059 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi All,

I have two validator .. one is compare validator and the other is regular expression validator.

The problem is if any validator fails it is showing both the error message. I need only particular message for that validator fails.

Please help me on this.
Note :- please let me know if I can do it except using CustomValidator.
In customValidator i have Clientsidevalidation where we can set the control disable , but I can not use the same (CustomValidator)

below is my code snippet

CSS
<asp:TextBox ID="txtid1" runat="server" MaxLength="15" ClientIDMode="Static">
                         <asp:RegularExpressionValidator ID="valAmountMaxValue" runat="server"
                            ValidationExpression="^\$?[0-9]{1,3}([,][0-9]{3})?([,][0-9]{3})?(\.[0-9]{2})$"
                            ControlToValidate="txtid1"
                            ErrorMessage=""
                            Display="None" />
                        <asp:CompareValidator ID="valAmountFromMustbeLessThanAmountTo" runat="server"
                        ErrorMessage=""
                        ControlToValidate="txtid1" ControlToCompare="txtid2" Type="Double" EnableClientScript="False"
                        Operator="LessThanEqual" Display="None" />
                        <asp:Label ID="lblAmountTo" runat="server" AssociatedControlID="txtAmountTo"> to
                        <asp:TextBox ID="txtid2" runat="server" MaxLength="15" placeholder="Optional" ClientIDMode="Static">


Up is my code .. i have two textbox where i have to validation for CompareValidator and RegularExpression. but i want a single message instead of both validation message.



Thanks,
Sandeep
Posted
Updated 10-Sep-14 22:39pm
v2

1 solution

You don't show any code, so not easy to see if you have done anything wrong.

This link might help you along
BaseValidator Class[^]
 
Share this answer
 
Comments
Sandeep Kumar Sinha 11-Sep-14 4:31am    
<asp:TextBox ID="txtid1" runat="server" MaxLength="15" ClientIDMode="Static">
<asp:RegularExpressionValidator ID="valAmountMaxValue" runat="server"
ValidationExpression="^\$?[0-9]{1,3}([,][0-9]{3})?([,][0-9]{3})?(\.[0-9]{2})$"
ControlToValidate="txtid1"
ErrorMessage=""
Display="None" />
<asp:CompareValidator ID="valAmountFromMustbeLessThanAmountTo" runat="server"
ErrorMessage=""
ControlToValidate="txtid1" ControlToCompare="txtid2" Type="Double" EnableClientScript="False"
Operator="LessThanEqual" Display="None" />
<asp:Label ID="lblAmountTo" runat="server" AssociatedControlID="txtAmountTo"> to
<asp:TextBox ID="txtid2" runat="server" MaxLength="15" placeholder="Optional" ClientIDMode="Static">


Up is my code .. i have two textbox where i have to validation for CompareValidator and RegularExpression. but i want a single message instead of both validation message.
George Jonsson 11-Sep-14 4:38am    
Why not use Improve Question and add this code there?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900