views:

201

answers:

1

I need to scroll to the top of the page after an Async Postback in an update panel. I've tried a couple of methods, and while they all scroll to the top of the page, they all get "overriden" by ASP.Net Ajax which returns the page to where it was when the postback occurs. I have already set MaintainScrollPositionOnPostBack="false" in the Page directive.

+1  A: 

Have you tried window.scrollTo(0, 0); ?

If you have, perhaps combine in with setTimeout

window.setTimeout("window.scrollTo(0, 0)", 3000);

Although I expect this might produce some ugly jumping around.

An alternative would be to hook into the EndRequest event handler

Sys.WebForms.PageRequestManager.getInstance().add_endRequest(EndRequestHandler);
function EndRequestHandler(sender, args)
{
    window.scrollTo(0, 0);
} 
Daniel Dyson
Yes, but as I said, ASP.Net scrolls back down to where the click occurred.
Payton Byrd
window.setTimeout("window.scrollTo(0, 0)", 3000);
Daniel Dyson
Setting the timeout worked! Yay!
Payton Byrd
Yes, but it is a workaround solution. It smells a bit. Could you try the other idea I had as well?
Daniel Dyson