Reputation: 1435
I want to scroll to top after post back. In my login page when I click on login button and if there is some validation error message then it scrolls to bottom. Not actually bottom it scroll down to first text field. I want to stop that default scrolling and want to scroll top. For that I am using following code:
<script type="text/javascript">
jQuery(document).ready(function () {
jQuery("#ScrollTop").val(0);
var prm = Sys.WebForms.PageRequestManager.getInstance();
prm.add_endRequest(function (s, e) {
jQuery("#ScrollTop").val(0);
window.scrollTo(0, 0);
$('html, body').animate({ scrollTop: 0 }, 'fast');
// alert('Postback end!');
});
prm.add_beginRequest(function (s, e) {
jQuery("#ScrollTop").val(0);
window.scrollTo(0, 0);
$('html, body').animate({ scrollTop: 0 }, 'fast');
});
});
This code is working fine but after endRequest page scroll to bottom. By using this code page scrolls to top and then middle of the page.
Please help me to resolve this.
Upvotes: 2
Views: 570
Reputation: 419
If its C# and asp.net, you might be after the property called MaintainScrollPositionOnPostBack
Upvotes: 1