ASP: How to use a single span or div element to display validation errors

262 Views Asked by At

I have a field that required 3 different validators: RequiredFieldValidator, RegularExpressionValidator, and CompareValidator.

Each validator has a "*" to show that something is wrong with the input:

<asp:TextBox ID="txtAddMin" runat="server" Width="30%" MaxLength="2"></asp:TextBox>
    <asp:RequiredFieldValidator ID="RequiredFieldValidator8" runat="server"  ErrorMessage="Min Value is missing" ControlToValidate="txtAddMin" ForeColor="Red" ValidationGroup="vgBinAdd">*</asp:RequiredFieldValidator>

    <asp:RegularExpressionValidator ID="RegularExpressionValidator8" runat="server" ErrorMessage="Invalid Min Value Entered" ControlToValidate="txtAddMin" ForeColor="Red" ValidationGroup="vgBinAdd" ValidationExpression="^[0-9]{2}$">*</asp:RegularExpressionValidator>

    <asp:CompareValidator ID="CompareValidator2" runat="server" ControlToValidate="txtAddMin" ControlToCompare="txtAddMax" Operator="LessThan" Type="Integer" ErrorMessage="Min Value shoule be less then MaxValue" ForeColor="Red" ValidationGroup="vgBinAdd">*</asp:CompareValidator>

Validations work as expected, however, when failing, the "" is displayed in different positions. So, when CompareValidator fails, the "" is displayed a few spaces from the input field.

Basically, every validator takes up some space after the input field and "*" is displayed with extra space before it based which validator fails.

IS that possible to fix that, so, the start is displayed in the fix position no matter which validator fails?

0

There are 0 best solutions below