ASP.net Postback - Scroll to Specific Position

后端 未结 9 1019
天命终不由人
天命终不由人 2020-12-15 16:50

I have an ASP.net WebForms page that has a lot of content on the top of the screen. It has a link button that will post back to the page and show another section of the page

相关标签:
9条回答
  • 2020-12-15 17:06

    I have

    <asp:MultiView ID="mvAriza" runat="server">
          <asp:View ID="View14" runat="server"> 
             ............ .......
          </asp:View>
    </asp:MultiView>
    

    on *.aspx page. And on the *.aspx.cs page on a button click.

    Page.SetFocus(mvAriza.ClientID);
    

    It works great.

    0 讨论(0)
  • 2020-12-15 17:07

    In your case I suggest you to keep the default value of Page.MaintainScrollPositionOnPostBack, and use the pure javascript scrolling function

    function scrollToDiv()
    {
        document.getElementById('yourDiv').scrollIntoView();
    }
    

    And call it at the page startup with a little delay of 1ms (pure javascript again)

    setTimeout(scrollToDiv, 1);
    

    And finally call it from the C# code behind, with the RegisterStartupScript (js executed after all the page has been loaded) :

    ScriptManager.RegisterStartupScript(Page, typeof(Page), "ScrollToADiv", "setTimeout(scrollToDiv, 1);", true);
    

    Like this, it will bypass any asp automatic scrolling

    0 讨论(0)
  • 2020-12-15 17:09

    Page.MaintainScrollPositionOnPostback = true seems to work just fine.

    0 讨论(0)
  • 2020-12-15 17:11

    You can use the code below if you have an anchor for the location:

    Page.ClientScript.RegisterStartupScript(this.GetType(), "hash", "location.hash = '#MOVEHERE';", true);
    
    0 讨论(0)
  • 2020-12-15 17:14

    This scroll automatically to desired Div in asp.net Control This is Function call it from Where you Want and also Download Java script file

    OnClientClick="return scrollGrid()"

    function scrollGrid1() { $('html,body').animate ( { scrollTop: $('#Div1').offset().top }, 'slow' ) }

    0 讨论(0)
  • 2020-12-15 17:20

    Page.MaintainScrollPositionOnPostBack = true; should take you back to the same position on the screen, but you could use AJAX, or you could use SetFocus() to focus on a specific control after the postback:

    http://msdn.microsoft.com/en-us/library/ms178232.aspx

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