troubleshooting Question

How to make CompareValidator not fire until Submit Button is clicked

Avatar of megnin
megninFlag for United States of America asked on
8 Comments1 Solution1667 ViewsLast Modified:
Hi Experts,

I made Multiple Choice Quiz using DropDownList controls for the answers.  I put both a RequiredFieldValidator and a CompareValidator on each question.

The problem is the CompareValidator fires and shows that the question is wrong as soon as you make a selection.  I don't want the CompareValidator to fire until the Submit Button is clicked.

If I add EnableClientScript="False" then the validator never fires and you can submit the form with wrong and unanswered questions.

I need the validation to not fire until the Submit Button is clicked, then show the questions that were not answered and not answered correctly.

Here in one question:
        <asp:RequiredFieldValidator ID="valQuestion01" runat="server" ControlToValidate="Question01" ErrorMessage="You did not answer Question #1." Text="&#9679;" Font-Bold="True" ForeColor="Red" />
        <asp:CompareValidator ID="comQuestion01" runat="server" ControlToValidate="Question01" ErrorMessage="The Answer for Question #1 is incorrect."
            Operator="Equal" Type="String" ValueToCompare="C" Text="&#9679;" Font-Bold="True" ForeColor="Red" BackColor="Yellow" />
        <asp:DropDownList ID="Question01" runat="server">
            <asp:ListItem Text="" />
            <asp:ListItem Text="BUDDY-SYSTEM" Value="Buddy-System" />
            <asp:ListItem Text="PIGGYBACKING" Value="C" />
            <asp:ListItem Text="COLUSION" value="Colusion"/>
            <asp:ListItem Text="PAYBACK" value="Payback"/>
        &nbsp;&nbsp;occurs when an authorized person permits someone to follow them through a door to a secure area.<br />

And submit button:
<asp:Button ID="SubmitButton" runat="server" Text="Submit" />

I tried every combination of CausesValidation and EnableClientScript I could think of and either nothing ever fires or the CompareValidator fires on every selection.

What's the trick?

Edgard Yamashita
Systems Analyst

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 1 Answer and 8 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 8 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros