Eric Robinson
Eric Robinson

Reputation: 2095

Asp.net Page moves down after load

I've noticed that after using <asp:panel> or <asp:UpdatePanel> my page is jumping/scrolling down after the page has finished rendering. Also after a asynchronous post back, the page moves to the same place instead of staying right where it is. I don't have any focus set in the code behind of my page.

It's probably worth mentioning that on page load I am updating some asp.net controls within the <asp:UpdatePanel>. Mostly database driven dropdowns.

I'm wondering if anyone knows of any reason why a page would jump down. Is there some default focus or something that happens to certain asp.net controls?

Thanks in advance for your help,

Things I've Tried:

How to keep whole page scroll position after asynchronous postback

Update1: I've used David Stratton script to get the correct position. However the page still jumps down then jumps back to the correct position. My goal is to have the page not jump at all.

This is the mark-up of my page, there are control between these.

<asp:UpdatePanel ID="UpdatePanel9" runat="server">

    <asp:Panel ID="tagpanel" runat="server" DefaultButton="btnAddTag">
    </asp:Panel>

</asp:UpdatePanel>
<asp:UpdatePanel ID="UpdatePanel5" runat="server">

    <asp:Panel ID="pnlIncidentInfo" runat="server">
    </asp:Panel>

</asp:UpdatePanel>

Upvotes: 2

Views: 2565

Answers (2)

David
David

Reputation: 73564

Note The issue described here is NOT related to the MaintainScrollPositionOnPostback. I've had this issue myself and it's related to the UpdatePanel control.

From http://weblogs.asp.net/andrewfrederick/archive/2008/03/04/maintain-scroll-position-after-asynchronous-postback.aspx

First, set up a div just inside the ContentTemplate named "scrollDiv".

  <asp:UpdatePanel ID="UpdatePanel1" runat="server">
     <ContentTemplate>
       <div id="scrollDiv">
          The rest of your page content goes here.
       </div>
     </ContentTemplate>
  <asp:UpdatePanel>

and then the JavaScript, as the article says, goes after the ScriptManager on your page

<script type="text/javascript">
    var xPos, yPos;
    var prm = Sys.WebForms.PageRequestManager.getInstance();
    prm.add_beginRequest(BeginRequestHandler);
    prm.add_endRequest(EndRequestHandler);
    function BeginRequestHandler(sender, args) {
        xPos = $get('scrollDiv').scrollLeft;
        yPos = $get('scrollDiv').scrollTop;
    }
    function EndRequestHandler(sender, args) {
        $get('scrollDiv').scrollLeft = xPos;
        $get('scrollDiv').scrollTop = yPos;
    }
</script>

Upvotes: 2

Mark Brackett
Mark Brackett

Reputation: 85665

Perhaps you're using MaintainScrollPositionOnPostBack?

Upvotes: 0

Related Questions