I'm building a webpage with ASP.net where, when the button at the top of the page, it automatically scrolls down to a certain :
<script>
function myFunction() {
const element = document.getElementById("Results");
element.scrollIntoView({behavior: 'smooth'});
}
</script>
But unfortunately, it goes back up again after the click. I have tried a number of solutions, like:
<script type="text/javascript">
var xPos, yPos;
var prm = Sys.WebForms.PageRequestManager.getInstance();
prm.add_beginRequest(BeginRequestHandler);
prm.add_endRequest(EndRequestHandler);
function BeginRequestHandler(sender, args) {
xPos = $get('scrollDiv').scrollLeft;
yPos = $get('scrollDiv').scrollTop;
}
function EndRequestHandler(sender, args) {
$get('scrollDiv').scrollLeft = xPos;
$get('scrollDiv').scrollTop = yPos;
}
</script>
or
MaintainScrollPositionOnPostback="true"
but to no avail.
My button is coded as:
<asp:Button ID="Button1" runat="server" Text="Button" OnClick="Button1_Click"
OnClientClick="myFunction()" Visible="true" Style="display: none" />
What other solutions should I try to implement?