ASP.NET AJAX UpdatePanel scrolling problem

后端 未结 5 688
春和景丽
春和景丽 2021-01-24 00:16

I\'ll try and be concise:

  1. I have a dropdownlist with Autopostback set to true
  2. I have an UpdatePanel that contains a Label<
相关标签:
5条回答
  • 2021-01-24 00:22

    Try MaintainScrollPositionOnPostback in one of these 3 ways

    • Programmatically - Page.MaintainScrollPositionOnPostBack = true;
    • Page declaration - <%@ Page MaintainScrollPositionOnPostback="true" %>
    • In the web.config - <pages maintainScrollPositionOnPostBack="true" />

    You may also need to add this javascript after the scriptmanager declaration:

    <script type="text/javascript">
    
    var prm = Sys.WebForms.PageRequestManager.getInstance();
    
    prm.add_beginRequest(beginRequest);
    
    function beginRequest()
    {
        prm._scrollPosition = null;
    }
    
    </script> 
    
    0 讨论(0)
  • 2021-01-24 00:25

    Velika - Sorry for the delay. If you are using a master page add :

    <asp:ScriptManagerProxy runat="server" ID="smp"></asp:ScriptManagerProxy>
    

    Otherwise just add

    <asp:ScriptManager runat="server" id="sm" />
    
    0 讨论(0)
  • 2021-01-24 00:26

    Had the exact same issue and got the answer. Hope this helps : http://forums.asp.net/p/1622050/4164858.aspx#4164858

     <script type="text/javascript">  
     var xPos, yPos;  
     var postBackElement;  
    
     var prm = Sys.WebForms.PageRequestManager.getInstance();  
     prm.add_endRequest(EndRequestHandler);  
     prm.add_initializeRequest(InitializeRequest);  
    
     function EndRequestHandler(sender, args) {  
         if (postBackElement != null) {  
             document.getElementById(postBackElement.id).focus();  
         }  
     }  
     function InitializeRequest(sender, args) {    
          postBackElement = args.get_postBackElement();    
      }            
    

    0 讨论(0)
  • 2021-01-24 00:32

    try this one

    <script type="text/javascript">
        var prm = Sys.WebForms.PageRequestManager.getInstance();
        prm.add_beginRequest(beginRequest);
    
        function beginRequest() {
            prm._scrollPosition = window.top;
        }
    </script> 
    
    0 讨论(0)
  • 2021-01-24 00:38
    public static void SetFocusByJavaScript(Page page, string clientID)
            {
                string uniqueScriptId = String.Concat("focusScript", clientID);
                string scriptBody = String.Format("setTimeout(\"$get('{0}').focus();\", 100);", clientID);
                ScriptManager.RegisterStartupScript(page, page.GetType(), uniqueScriptId, scriptBody, true);
            }
    

    This is how I have been getting around this issue. The example requires jquery, but you could rewrite if needed. Basically just delays the focus script.

    0 讨论(0)
提交回复
热议问题