ASP.Net validation summary causes page to jump to top

前端 未结 9 1051
时光说笑
时光说笑 2020-12-08 06:09

I have a simple form with a few required field validators and a validation summary control. When I submit the form, the client validation will cause the form to ju

9条回答
  •  一向
    一向 (楼主)
    2020-12-08 07:09

    As stated by cleek's answer, this is a known bug having workarounds.

    Here is bdukes one, which looks to me as the best currently available.

    (function () {
      var originalValidationSummaryOnSubmit = window.ValidationSummaryOnSubmit;
      window.ValidationSummaryOnSubmit = function (validationGroup) {
        var originalScrollTo = window.scrollTo;
        window.scrollTo = function() { };
        originalValidationSummaryOnSubmit(validationGroup);
        window.scrollTo = originalScrollTo;
      }
    }());
    

    (He has not posted it directly here on SO, and now the connect issue seems to require registration for being seen, which renders his workaround harder to access.)

提交回复
热议问题