Solved

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

Posted on 2008-06-26
5
162 Views
Last Modified: 2011-10-19
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

0
Comment
Question by:copyPasteGhost
  • 2
  • 2
5 Comments
 
LVL 1

Expert Comment

by:ryanfinn1979
ID: 21873625
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

0
 
LVL 13

Author Comment

by:copyPasteGhost
ID: 21873683
:) 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
0
 
LVL 22

Expert Comment

by:prairiedog
ID: 21875086
Set the "Display" property of the two validators to "Dynamic" to see if it will help.
0
 
LVL 1

Accepted Solution

by:
ryanfinn1979 earned 500 total points
ID: 21875730
Try setting Display="Dynamic" and turning off text wrapping for the column - <td style="white-space: nowrap">
        <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 style="white-space: nowrap">

                    <asp:RequiredFieldValidator ID="reqValEmail" runat="server" ControlToValidate="txtEmail"

                        ErrorMessage="Please enter a valid email address." Display="Dynamic"></asp:RequiredFieldValidator><asp:RegularExpressionValidator ID="regValEmail" runat="server" ControlToValidate="txtEmail"

                        ErrorMessage="Please enter a valid email address." ValidationExpression="\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*" Display="Dynamic"></asp:RegularExpressionValidator>

                </td>

            </tr>

        </table>

Open in new window

0
 
LVL 22

Expert Comment

by:prairiedog
ID: 21875819
So setting "Display=Dynamic" like I said in my post helped?
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I recently went through the process of creating a Calendar Control of events with the basis of using a database to keep track of the dates that are selectable, one requirement was to have the selected date pop-up in a simple lightbox.  At first this…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, just open a new email message. In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…

910 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now