user1292656
user1292656

Reputation: 2560

Go to Top of Page when is postback

I have an ascx control which has inside a Save Button and it is at the bottom of the page. When i click the save button and it postbacks the control remains at the bottom. Is that any whay to go to top after postback?

Upvotes: 4

Views: 4070

Answers (1)

Alexander Manekovskiy
Alexander Manekovskiy

Reputation: 3203

Such behaviour could be because of page property MaintainScrollPositionOnPostback set to true. This property could be set either programmatically or declaratively throught web.config or via page directive:

Page.MaintainScrollPositionOnPostBack = true;
<%@ Page MaintainScrollPositionOnPostback="true" %>
<pages maintainScrollPositionOnPostBack="true" /> 

Check these things, I believe somewhere it is enabled.

Alternatively you can your subscribe to the endRequest "event" on your page and reset scroll position on each request.

<script>
    var prm = Sys.WebForms.PageRequestManager.getInstance();
    prm.add_endRequest(function () {
        window.scrollTo(0, 0);
    });
</script>

Upvotes: 3

Related Questions