ASP.NET: CompareValidator and ValidationSummary
<p>I got some odd behaviour with a CompareValidator and a ValidationSummary.</p>

<p>For instance the below .aspx file (there is no relevant C# codebehind, so just past the below code in the  a new .aspx file, run and watch the behaviour).</p>

<p>And these (refined) steps:</p>

<ol>
<li>Press F5 to start the app;</li>
<li>Click the button;</li>
<li>Left mouse click in the left text box;</li>
<li>Type foo;</li>
<li>Left mouse click in the right text box;</li>
<li>Type bar;</li>
<li>Click the button (now the summary is not right);</li>
<li>Click the button again (now the summary is right, but you do NOT get a post back as not all of the validation requirements are yet met).</li>
</ol>

<p>These steps have a tiny bit different result, because the focus change is by keyboard:</p>

<ol>
<li>Press F5 to start the app;</li>
<li>Click the button;</li>
<li>Left mouse click in the left text box to focus it;</li>
<li>Type foo;</li>
<li>Press the Tab key to move to the focus to the right text box;</li>
<li>Type bar;</li>
<li>Press the Tab key to move to the focus to the button (now the summary is not right);</li>
<li>Click the button (now the summary is right, but you do NOT get a post back as not all of the validation requirements are yet met).</li>
</ol>

<p>Why do you need two actions to the Submit button (one action to get it focussed, one to click it) to get the ValidationSummarry updated?</p>

<p><em>(Old steps for comparison:
 1. Enter nothing in both textboxes, then press the SubmitButton
 2. Now you get a bulleted list in the validation summary, and two validation lines in front of the SubmitButton
 3. Now enter "foo" in TextBox1 and "bar" in TextBox2, then press the SubmitButton
 4. Now you keep the two items in the bulleted list, and "Both textbox values should be same." in front of the SubmitButton
 5. Now press the SubmitButton again
 6. Now the ValidationSummary correctly contains "Both textbox values are not equal."
Ad 4: why doesn't the ValidationSummary contain only one bullet "Both textbox values should be same."?
)</em></p>

<pre><code>    &lt;asp:ValidationSummary ID="ValidationSummary" runat="Server" ShowSummary="true" DisplayMode="BulletList" /&gt;
    &lt;asp:Label ID="lbl" AssociatedControlID="TextBox1" runat="Server" Text="Write into TextBox" /&gt;
    &lt;asp:TextBox ID="TextBox1" runat="Server" /&gt;
    &lt;asp:TextBox ID="TextBox2" runat="Server" /&gt;
    &lt;asp:RequiredFieldValidator ID="req1" runat="Server" ControlToValidate="TextBox1"
        ErrorMessage="1st TextBox is Mandatory field" Text="&lt;br&gt;Please write something in 1st  Box." /&gt;
    &lt;asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="Server" ControlToValidate="TextBox2"
        ErrorMessage="2nd TextBox is Mandatory field" Text="&lt;br&gt;Please write something in 2nd Box." /&gt;
    &lt;asp:CompareValidator ID="CompareValidator1" runat="Server" ControlToValidate="TextBox2"
        ControlToCompare="TextBox1" Operator="Equal" Type="string" Text="Both textbox values should be same."
        ErrorMessage="Both textbox values are not equal." Display="Dynamic" /&gt;
    &lt;asp:Button ID="SubmitButton" runat="Server" Text="Submit" /&gt;
</code></pre>

<p>Note: Adding a ValidationGroup does not help:</p>

<pre><code>        &lt;asp:ValidationSummary ID="ValidationSummary" runat="Server" ValidationGroup="All" ShowSummary="true" DisplayMode="BulletList" /&gt;
        &lt;asp:Label ID="lbl" AssociatedControlID="TextBox1" runat="Server" Text="Write into TextBox" /&gt;
        &lt;asp:TextBox ID="TextBox1" runat="Server" /&gt;
        &lt;asp:TextBox ID="TextBox2" runat="Server" /&gt;
        &lt;asp:RequiredFieldValidator ID="req1" runat="Server" ValidationGroup="All" ControlToValidate="TextBox1"
            ErrorMessage="1st TextBox is Mandatory field" Text="&lt;br&gt;Please write something in 1st  Box." /&gt;
        &lt;asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="Server" ValidationGroup="All" ControlToValidate="TextBox2"
            ErrorMessage="2nd TextBox is Mandatory field" Text="&lt;br&gt;Please write something in 2nd Box." /&gt;
        &lt;asp:CompareValidator ID="CompareValidator1" runat="Server" ValidationGroup="All" ControlToValidate="TextBox2"
            ControlToCompare="TextBox1" Operator="Equal" Type="string" Text="Both textbox values should be same."
            ErrorMessage="Both textbox values are not equal." Display="Dynamic" /&gt;
        &lt;asp:Button ID="SubmitButton" runat="Server" Text="Submit" ValidationGroup="All" /&gt;
</code></pre>

<p>Anyone?</p>
