ASP.Net validation summary causes page to jump to top
Two possible work arounds:
Disable client validation and jump to correct position on post back:
* set EnableClientScript="false" for all validation controls (disabling client validation)* set MaintainScrollPositionOnPostback="true" in Page directive
Disable the scrollTo function in javascript:
<script type="text/javascript"> window.scrollTo = function() { }</script>
This is a known bug, as documented on Microsoft Connect. The relevant issue has the basis for the best work around:
var ValidationSummaryOnSubmitOrig = ValidationSummaryOnSubmit;var ValidationSummaryOnSubmit = function() { var scrollToOrig = window.scrollTo; window.scrollTo = function() { }; var retVal = ValidationSummaryOnSubmitOrig(); window.scrollTo = scrollToOrig; return retVal;}
Instead of
<script type="text/javascript"> window.scrollTo = function() { return true; }</script>
which would indiscriminately override the ScrollTo function for all postbacks, I put the function in my OnClientClick event of the button. As below.
onClientClick="window.scrollTo = function(x,y) { return true; };"
Not sure if it's the best solution, but it seems to have done the job for me.