zoukankan      html  css  js  c++  java
  • 解决ValidationSummary Control 发生时,页面置顶问题, 即:window.scrollTo(0, 0)

       If we use ValidationSummary control to show error or invalid message on page, but the page will jump to top when click button.

      If you find build code in webResource file, will find the rease is that the code is window.scrollTo(0,0), so the page jump to top.

       How to solve the issue?

       We will see on the position of control with (X,Y) point or don't reset the point it is.

       1. If you are not using window.scrollTo() in your page, you can redefine the function to be a no-op. Just   

           add "window.scrollTo = function() { }" to the JavaScript code on your page.

       2. Alternatively, you can just redefine window.scrollTo for the duration of the ASP.NET Validators javaScript execution, like so:
      

    代码
    1 var ValidationSummaryOnSubmitOrig = ValidationSummaryOnSubmit;
    2 var ValidationSummaryOnSubmit = function() {
    3     var scrollToOrig = window.scrollTo;
    4     window.scrollTo = function() { };
    5     ValidationSummaryOnSubmitOrig();
    6     window.scrollTo = scrollToOrig;
    7 }
    8 

    3. Instead of overriding window.scrollTo(), you can instead call focus() on an element (like the invalid control or the validation summary) after the call to window.scrollTo() has occured.

    1 var Page_ClientValidateOrig = Page_ClientValidate;
    2 var Page_ClientValidate = function() {
    3     var v = Page_ClientValidateOrig();
    4     Page_InvalidControlToBeFocused.focus();
    5     return v;
    6 }
  • 相关阅读:
    ! JOISC2020DAY2变色龙之恋
    ! JOISC2020DAY1扫除
    JOISC2020DAY1汉堡肉
    JOISC2020DAY1建筑装饰4
    ! JLOI/SHOI2016随机序列
    JLOI/SHOI2016黑暗前的幻想乡
    ! JLOI/SHOI2016成绩比较
    JLOI/SHOI2016方
    JLOI/SHOI2016侦查守卫
    ! AHOI/HNOI2017抛硬币
  • 原文地址:https://www.cnblogs.com/OSoft/p/1675541.html
Copyright © 2011-2022 走看看