简体   繁体   中英

Mandatory field icon Display 3 times

I am developing a simple webform for adding a candidate. In my Add Candidate form, I am using 3 buttons - two buttons for saving a data, and one button for cancel. On two buttons two different validations groups are used. when I am clicking on first button, proper validation group called and when I am clicking on second button then also it works fine. However, when I am entering a wrong value in textbox then it will show 2 validation messages but I want to show only one message like below:

在此处输入图片说明

Markup:

<TextBox ID="txtDateofBirth" runat="server" Width="120" CssClass="form-control" MaxLength="10" placeholder="MM/DD/YYYY" onblur="javascript: ValidateDate(this);" onkeypress="return IsNumeric(event, this);" ondrop="return false;" onpaste="return false;"></asp:TextBox>
                        <asp:CompareValidator ID="CompareValidator1" runat="server" ErrorMessage="You must enter a valid Date Of Birth"
                            Display="Dynamic" ControlToValidate="txtDateofBirth" Operator="DataTypeCheck" Type="Date" ForeColor="Red" ValidationGroup="Validations">!</asp:CompareValidator>
                        <asp:CompareValidator ID="cmpDateOfBirth" runat="server" ErrorMessage="Entered Date Of Birth must be greater than 20 years"
                            Display="Dynamic" ControlToValidate="txtDateofBirth" Operator="LessThanEqual" ValueToCompare='<%# DateTime.Now.Subtract(TimeSpan.FromDays(7300)) %>' Type="Date" ForeColor="Red" ValidationGroup="Validations">!</asp:CompareValidator>
                        <asp:RequiredFieldValidator ID="rfvDateofBirth" runat="server" ErrorMessage="Please Enter Date of Birth"
                            ValidationGroup="Validations" ControlToValidate="txtDateofBirth" ForeColor="#CC0000" Display="Dynamic">!</asp:RequiredFieldValidator>
                        <asp:ImageButton ID="imgDateofBirth" TabIndex="4" ImageUrl="~/Images/calendar.png" 
                            AlternateText="Click here to display Calendar" runat="server" CausesValidation="False" />
                        <ajaxcontrol:CalendarExtender ID="CEDateofBirth" runat="server" FirstDayOfWeek="Monday"  
                            Format="MM/dd/yyyy" TargetControlID="txtDateofBirth"
                            PopupButtonID="imgDateofBirth">
                        </ajaxcontrol:CalendarExtender>

您能否参考以下验证组教程http://csharp-video-tutorials.blogspot.in/2012/11/validationgroups-in-aspnet-part-50.html希望它对您有用!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM