Field Validators Disabled with Display Instead of Visibility
ASP.NET’s Field validators are super useful, but one thing has always bothered me. By default when they don’t want the control to display it sets the style of the element to “visibility:hidden“. This is a problem most of the time, as the HTML element still occupies that space on the screen, it’s just invisible. My preference is for it to be “display:none” as it will no longer take up space in the DOM and other elements will flow into it’s place (ie. other required field validators).
<asp:RequiredFieldValidator ID="valFirstNameReq" runat="server" ControlToValidate="txbFirstName" SetFocusOnError="true" ErrorMessage="Please enter your first name." Display="Dynamic" ValidationGroup="cgstpForm" />
There it is. The property Display=”Dynamic” on a validation control switches it to this method. I found the naming of this to be non intuitive, since display set to dynamic makes sense now that i know it, but i never would have thought it had to do with this.