How can I get back to the same position of a page on postback
. It always seems to get to the top of the page.
I\'ve tried using maintainSc
Although bbbwex's reply is correct, it actually took me a while to realize I need to place MaintainScrollPositionOnPostback="true" at both
Top of the ASPX page.
In IsPostBack
It works after I satisfy both condition.
Best solution for me, was to wrap the problematic controls with an update panel
<asp:UpdatePanel runat="server" id="UpdatePanel" updatemode="Conditional">
<ContentTemplate>
dropdown controls that cause postback etc..
</ContentTemplate>
</asp:UpdatePanel>
ofcourse, you also need the
<asp:ScriptManager ID="ScriptManager1" runat="server" />
to be present inside the main form of the site.
Note: If you have a default control defined, it will scroll to that control on post back even if Page MaintainScrollPositionOnPostback="true"
There are a few ways I have used to set maintainScrollPositionOnPostBack. Have you tried more than one? Can you describe what is triggering the postback and which browsers you have tested? Are you using a master page?
Page.MaintainScrollPositionOnPostBack = true;
in the code behind on page load.<%@ Page MaintainScrollPositionOnPostback="true" %>
<pages maintainScrollPositionOnPostBack="true" />
You can set .Focus() onto a specific server control when your page posts back.
Make sure, that you do not set default button in <form id="form1" runat="server" defaultbutton="YourDefaultButton">
. Remove defaultbutton="YourDefaultButton"
and MaintainScrollPositionOnPostback="true"
will work.