Unwanted spaces added by Validators

Discussion in 'ASP .Net' started by tshad, Jan 26, 2005.

  1. tshad

    tshad Guest

    I have the following on one of my Textboxes:

    <asp:RequiredFieldValidator
    ControlToValidate="email"
    Text="Email Required"
    runat="server" />
    <asp:RegularExpressionValidator ControlToValidate="email" Text =
    "Invalid Email Address!"
    ValidationExpression="\S+@\S+\.\S{2,3}" runat="server" />
    <asp:CustomValidator
    ControlToValide="email"
    OnServerVAlidate="ValidateEmail"
    Display="Dynamic"
    Text="Email already on File"
    runat="server" />

    I also have Required validators on 2 Textboxes above this one. If I don't
    enter anything, all the error messages line up. If I enter something, but
    one that in invalidated, I get a "&nbsp;" where the RequiredValidator is.
    This happens no matter what order I do it. If the Validator doesn't print a
    message, it prints a space.

    Is there some way to stop this? It just makes the page look out of line.

    Thanks,

    Tom
     
    tshad, Jan 26, 2005
    #1
    1. Advertisements

  2. tshad

    IPGrunt Guest

    Have you tried laying out using tables?

    --
     
    IPGrunt, Jan 26, 2005
    #2
    1. Advertisements

  3. tshad

    tshad Guest

    They are in a table.

    Here is more of a snippet with 3 of the objects:

    ***************************************************************************
    <tr>
    <td align="right">Email Address: </td>
    <td><asp:textbox id="txtEmail" TextMode="SingleLine" Columns="32"
    runat="server" />
    <asp:RegularExpressionValidator
    ControlToValidate="txtEmail"
    Font-Size="10"
    Text = "Invalid Email Address!"
    ValidationExpression="\S+@\S+\.\S{2,3}"
    runat="server" />
    <asp:RequiredFieldValidator
    ControlToValidate="txtEmail"
    Font-Size="10"
    Text="You must enter an email"
    runat="server" />
    </td>
    </tr>
    <tr>
    <td align="right">Password</td>
    <td><asp:textbox id="txtPassword" TextMode="Password"
    Columns="32" runat="server" />
    <asp:RequiredFieldValidator
    ControlToValidate="txtPassword"
    Text="You must enter an password"
    Font-Size="10"
    runat="server" />
    <asp:CustomValidator
    ControlToValidate="txtEmail"
    OnServerValidate="ValidateEmail"
    Font-Size="10"
    Display="Dynamic"
    Text="Not Valid !"
    runat="server" />
    </td>
    </tr>
    <tr>
    <td>&nbsp;</td>
    <td><asp:CheckBox ID="SaveLogon" Runat=server
    />&nbsp;&nbsp;Remember Me?</td>
    </tr>
    *************************************************************************

    Tom
     
    tshad, Jan 27, 2005
    #3
  4. tshad

    IPGrunt Guest

    What I do is use the static display. This way i know how much space they'll
    take up. Dynamic display doesn't always work like you think it will.

    -- ipgrunt
     
    IPGrunt, Jan 27, 2005
    #4
  5. tshad

    tshad Guest

    I tried changing both to static and I still get the same thing.

    If I change the order, it works ok, only the &nbsp; is placed after the
    message, instead of before. Here is what gets generated:
    ********************************************************
    <td><input name="txtEmail" type="text" size="32" id="txtEmail" />
    <span><font color="Red" size="2">You must enter an
    email</font></span>
    &nbsp;
    </td>
    ********************************************************************

    Tom
     
    tshad, Jan 27, 2005
    #5
  6. tshad

    IPGrunt Guest

    Have you considered putting the control and the validator in different
    columns?

    --
     
    IPGrunt, Jan 27, 2005
    #6
  7. tshad

    tshad Guest

    If I do that, the second message will show way over to the right.

    Tom
     
    tshad, Jan 27, 2005
    #7
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.