ASP.NET validator alignment issue

I am developing a contactus webpage that has an input field called Email. It is checked using the required validation module and validation of regular expressions with corresponding messages.

Required: enter email address Regular expression: invalid email address

I install these two as follows:

<asp:TextBox ID="txtEmail" runat="server"></asp:TextBox> <font color="#FF0000">*</font> <asp:RequiredFieldValidator ID="rfvemail" CssClass="error_text" ControlToValidate="txtEmail" runat="server" ErrorMessage="Enter email address."></asp:RequiredFieldValidator> <asp:RegularExpressionValidator ID="revemail" runat="server" ControlToValidate="txtEmail" ErrorMessage="Invalid Email" ValidationExpression="\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*"></asp:RegularExpressionValidator> 

My problem is that Enter Email and Invalid Email occupy their own space. For example: if I leave the email address as an empty space and click the "Send" button, "Enter Email" is displayed next to it. If I enter an invalid email address (xxx), enter “Send Email”, but select a space, the message “Invalid Email” will appear after this “Enter Email Address” space before.

Is there any way to remove this space?

Mahesh

+4
source share
3 answers

Use Diplay = "Dynamic"

Display behavior for inspection verification. Legal Values:

  • No (the control is not displayed. Used to display an error message only in ValidationSummary)
  • Static (the control displays an error message if the verification fails. It is reserved on the page for the message, even if the input passes the verification.
  • Dynamic (the control displays an error message if the verification does not complete. It is reserved on the page for the message if the input passes the verification
+3
source

If I understand the question correctly, I think the answer is to set the Display property to Dynamic .

If you use ASP.NET themes, you can set this default value for all validators in your theme using the Skin file, so you no longer have to worry about it.

+2
source

Source: https://habr.com/ru/post/1309425/


All Articles