ASP.net Postback - Scroll to Specific Position ASP.net Postback - Scroll to Specific Position asp.net asp.net

ASP.net Postback - Scroll to Specific Position


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


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

Page.ClientScript.RegisterStartupScript(this.GetType(), "hash", "location.hash = '#MOVEHERE';", true);


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