Programmatically scroll to an Anchor Tag

Using javascript:

window.location.href = '#label2';

If you need to do it from the server/code behind, you can just emit this Javascript and register it as a startup script for that page.


This JS has generally worked well for me if you also put an ID on the element:

document.getElementById('MyID').scrollIntoView(true);

This is good as it will also position scrollable divs etc so that the content is visible.


Moving to a anchor from server side, example is c#.

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