views:

98

answers:

3

Hi,

I am developing contactus webpage which have a input field called Email. It is validated against a required field validator and regular expression validator with appropriate messages.

Required: Enter Email Regular Expression: Invalid Email

I am setting these two as given below:

<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 both Enter Email and Invalid Email is occupying its own space. For Ex: If I leave email as empty space and press submit, Enter Email is displaying right next to it. If I enter invalid email(xxx), Enter Email is off but taking the space, Invalid Email message is displayed after these space taken by 'Enter Email' before.

Is there any way to remove this space??

Mahesh

+1  A: 

Use Diplay = "Dynamic"

The display behavior for the validation control. Legal values are:

  • None (the control is not displayed. Used to show the error message only in the ValidationSummary control)
  • Static (the control displays an error message if validation fails. Space is reserved on the page for the message even if the input passes validation.
  • Dynamic (the control displays an error message if validation fails. Space is not reserved on the page for the message if the input passes validation
Claudio Redi
+1  A: 

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

If you're using ASP.NET Themes, you can set this as the default for all validators in your Theme using a Skin file, so you never have to worry about it again.

Greg