Link to home
Start Free TrialLog in
Avatar of copyPasteGhost
copyPasteGhostFlag for Canada

asked on

Have validation start on same position on page ASP.NET 2.0

I want to have my validation stacked on top of eachother.

What happens here is that when no email is entered it displays the message fine.. but when the email is not valid is displays the message after the "RequiredFieldValidator" message. which looks stupid.

Does anyone know how to fix this?

Thanks,
<table>
    <tr>
        <td style="text-align: right">
            <asp:Label ID="lblEmail" runat="server" AssociatedControlID="txtEmail"></asp:Label><span style="color:Red">*</span>
        </td>
        <td>
            <asp:TextBox ID="txtEmail" runat="server"></asp:TextBox>
        </td>
        <td>
            <asp:RequiredFieldValidator ID="reqValEmail" runat="server" ControlToValidate="txtEmail"
                ErrorMessage="RequiredFieldValidator"></asp:RequiredFieldValidator>
            <asp:RegularExpressionValidator ID="regValEmail" runat="server" ControlToValidate="txtPayPalAcc"
                ErrorMessage="RegularExpressionValidator" ValidationExpression="\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*"></asp:RegularExpressionValidator>
        </td>
    </tr>
</table>

Open in new window

Avatar of Ryan Finn
Ryan Finn
Flag of United Kingdom of Great Britain and Northern Ireland image

Your RegularExpressionValidator is validating the wrong control - it is currently validating txtPayPalAcc instead of txtEmail.

It's probably a good idea to choose a more user friendly error message such as "Please enter a valid email address." instead of "RegularExpressionValidator".
<table>
    <tr>
        <td style="text-align: right">
            <asp:Label ID="lblEmail" runat="server" AssociatedControlID="txtEmail"></asp:Label><span style="color:Red">*</span>
        </td>
        <td>
            <asp:TextBox ID="txtEmail" runat="server"></asp:TextBox>
        </td>
        <td>
            <asp:RequiredFieldValidator ID="reqValEmail" runat="server" ControlToValidate="txtEmail"
                ErrorMessage="Please enter a valid email address."></asp:RequiredFieldValidator>
            <asp:RegularExpressionValidator ID="regValEmail" runat="server" ControlToValidate="txtEmail"
                ErrorMessage="Please enter a valid email address." ValidationExpression="\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*"></asp:RegularExpressionValidator>
        </td>
    </tr>
</table>

Open in new window

Avatar of copyPasteGhost

ASKER

:) I do. the text is coming from the database. I changed it...

it's still doing the same thing...I included a picture of the problem.

Thanks
email-problem.GIF
Set the "Display" property of the two validators to "Dynamic" to see if it will help.
ASKER CERTIFIED SOLUTION
Avatar of Ryan Finn
Ryan Finn
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
So setting "Display=Dynamic" like I said in my post helped?