It is quite simple to accomplish this using the ScriptManager's registerStartupScript method.
To reset the scroll position (back to top), add the following code to your postback event:
ScriptManager.RegisterStartupScript(UpdatePanel1, this.GetType(), "ScrollTop", "setTimeout('window.scrollTo(0,0)', 0);", true);
If you use jQuery you can use the following code to scroll to the top of a specific element (with the ID mydiv in this example), no plugin required:
ScriptManager.RegisterStartupScript(UpdatePanel1, this.GetType(), "ScrollTop", "setTimeout(\"$('html, body').scrollTop($('#mydiv').offset().top)\", 0);", true);
Using jQuery opens up many other options, including animating the scroll position.
NB. In the above examples change UpdatePanel1 to the ID of your UpdatePanel.
If this tip helped you please share on Facebook, Twitter or Google+.
by John Avis | May 6, 2020
If you are having intermittent problems sending email in .NET using System.Net.Mail consider switching libraries.
by John Avis | November 4, 2019
As support ends for Microsoft Windows Server 2008 I have recently gone through migrating some websites to a new server running Windows Server 2016 and IIS 10 but some of the websites did not work.
by John Avis | October 15, 2019
For a website project I needed a way to enter multiple tags. I just wanted something simple that I could easily modify to suit my own needs, so I wrote my own.