Reputation: 2145
hi im have a very common problem but unable to find any answer i have a div and there are validator controls in it. I have used br tag in ErrorMessage Text to show show each message in new line. My code is below
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" CssClass="lblMessageError"
runat="server" ErrorMessage="<br> User name field cannot be empty" ControlToValidate="txtUserName" SetFocusOnError="True"></asp:RequiredFieldValidator>
<asp:CustomValidator ID="CustomValidator1" runat="server" ClientValidationFunction="ClientValidate" ControlToValidate="txtPassword" CssClass="lblMessageError" ErrorMessage="<br />The password must be more than 6 characters."></asp:CustomValidator>
<asp:CompareValidator ID="CompareValidator1" runat="server" CssClass="lblMessageError" ControlToCompare="txtPassword" controlToValidate="txtRePassword" ErrorMessage="<br /> Password dont match with repassword"></asp:CompareValidator>
</div>
when there is no error found then it show line breaks. all i want is when there is not error found line breaks are ommitted.
1) when all validators are hidden
'<%--line Break because no error found--%>
'<%--line Break because no error found--%>
' <%--line Breakbecause no error found---%>
2) when one validator is visible and other and hidden
User name field cannot be empty
' <%--line Break because no error found--%>
' <%--line Breakbecause no error found---%>
'<%-- ally my controls here--%>
and i also dont want to show all my errors in same line any suggestions??
Upvotes: 0
Views: 2795
Reputation: 16726
Add the Display="Dynamic"
attribute to your validator, eg:
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" CssClass="lblMessageError"
runat="server" Display="Dynamic" ErrorMessage="<br> User name field cannot be empty" ControlToValidate="txtUserName" SetFocusOnError="True"></asp:RequiredFieldValidator>
Upvotes: 2