ASP.NET AJAX UpdatePanel scrolling problem

无人久伴 提交于 2019-12-02 06:35:27

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> 

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" />

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();    
  }            

usman

try this one

<script type="text/javascript">
    var prm = Sys.WebForms.PageRequestManager.getInstance();
    prm.add_beginRequest(beginRequest);

    function beginRequest() {
        prm._scrollPosition = window.top;
    }
</script> 
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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!