Validation controls - set focus on specific anchor
<p>I using ASP.NET Validation Controls to validate fields on a form and I need to set the focus on a specific anchor within my page, but it keeps moving to the top of the page even though <code>SetFocusOnError</code> is set to <strong>True</strong>. I tried adding a <code>CustomValidator</code> with a <code>ClientValidationFunction</code> but it runs before validation hence moving back to the top of the page.</p>

<p>I also tried this:</p>

<p><a href="http://stackoverflow.com/questions/3473874/set-focus-to-validation-summary">Set focus to validation summary?</a></p>

<p>But the first link is no longer available and the second one just don't work (<strong>That's why answers should be self contained!</strong>).</p>

<p>Here are samples of my code:</p>

<pre><code>    &lt;asp:ValidationSummary ID="ValidationSummary1" ClientIDMode="Static"
    runat="server" HeaderText="[custom message in my native language]"
    ValidationGroup="Valida" CssClass="msg_erro" /&gt;

    &lt;asp:RequiredFieldValidator ID="vldNome" runat="server"
    ControlToValidate="txtNome" ValidationGroup="Valida" Display="Dynamic"
    ErrorMessage="blah blah blah" SetFocusOnError="True" Text="*" /&gt;

    //a bunch o others validatiors...

    &lt;asp:ImageButton runat="Server"
    ImageUrl="~/img/anuncie/btn-cadastrar.png" ID="btnEnviar"
    ValidationGroup="Valida" CssClass="btn-cadastrar" /&gt;
</code></pre>

<p>As I said, I need the focus to be on a specific anchor but setting the focus on the <code>ValidationSummary</code> or on any field would be nice as well because my fields start far from the top of the page.</p>

<p>Thanks.</p>

<p><strong>UPDATE</strong></p>

<p>Different behavior in different browsers:</p>

<ul>
<li>IE - Focus is correctly set on fields when clicking on submit (depending on IE version)</li>
<li>FF - Clicking on submit for the first time moves to the top of the page, second time and on, it set the focus on the fields.</li>
<li>Chrome - Never works.</li>
</ul>
