Note that there are some explanatory texts on larger screens.

plurals
  1. POASP.Net validation summary causes page to jump to top
    primarykey
    data
    text
    <p>I have a simple form with a few required field validators and a validation summary control. When I submit the form, the <em>client</em> validation will cause the form to jump to the top of the page. If i remove the validation summary, the page does not move.</p> <p>Heres a quick example:</p> <pre><code>&lt;asp:TextBox ID="test" runat="server"&gt;&lt;/asp:TextBox&gt; &lt;asp:RequiredFieldValidator ID="testrequired" runat="server" ControlToValidate="test"&gt;*&lt;/asp:RequiredFieldValidator&gt; &lt;asp:ValidationSummary ID="summary" runat="server" /&gt; &lt;asp:Button ID="submit" runat="server" Text="submit" /&gt; </code></pre> <p>I've tried setting <code>SetFocusOnError="true"</code> in the required field validator and <code>MaintainScrollPositionOnPostback="true"</code> for giggles - even though this isn't a postback - without any luck. Is there a known solution for this problem?</p> <p><strong>EDIT:</strong></p> <p>I've found the problem in the js generated by WebResource.axd. Seems to come down to a single line in the <code>ValidationSummaryOnSubmit()</code> function.</p> <pre><code>line 534: window.scrollTo(0,0); </code></pre> <p>Any ideas on how to remove or bypass this?</p> <p><strong>EDIT2:</strong></p> <p>Quick work around for the time being:</p> <ul> <li>set <code>EnableClientScript="false"</code> for all validation controls (disabling client validation)</li> <li>set <code>MaintainScrollPositionOnPostback="true"</code> in Page directive</li> </ul> <p>Still hoping for a client side solution...</p> <p><strong>EDIT3:</strong></p> <p>It seems a better work around is to just override the <code>window.scrollTo()</code> function so that it does nothing when called by the validation script:</p> <pre><code>&lt;script type="text/javascript"&gt; window.scrollTo = function() { } &lt;/script&gt; </code></pre> <p>Adding the above anywhere on the page leaves the client validation in tact, but disables the <code>window.scrollTo()</code> method throughout the page</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload