Link to home
Start Free TrialLog in
Avatar of jimmieandersson
jimmieandersson

asked on

Scroll to top when update inside update panel

I have a repeater that is placed inside an update panel.
When I click at one of the buttons inside this I want the page to be scrolled to the top.

I have googled a solution: (see code)

The problem with this solution is that it respond to all updates. I want it to execute just when the user clicks a specific button..

somebody knows a easy solution?
<script type="text/javascript" language="javascript">
  Sys.WebForms.PageRequestManager.getInstance().add_endRequest(EndRequestHandler);
  function EndRequestHandler(sender, args)
  {
  scrollTo(0,0);
  }
</script>

Open in new window

Avatar of Praveen Venu
Praveen Venu
Flag of India image

simple.. In the button1_click after all other code execute

Page.RegisterStartUpScript("scr","<script>scrollTo(0,0);</script>")

Avatar of jimmieandersson
jimmieandersson

ASKER

thanks, I changed your script a little to:

ScriptManager.RegisterClientScriptBlock(uplShoppingCart, this.GetType(), "scrToTop", "<script>scrollTo(0,0);</script>", false);


what happens now is that the page first scroll to the top but only stays until the page is fully loaded again (<1 sec). It then goes back to the original scroll position.
check to see if your URL has any #

else
 try

System.Web.UI.Page.MaintainScrollPositionOnPostBack = false;
ScriptManager.RegisterClientScriptBlock(uplShoppingCart, this.GetType(), "scrToTop", "<script>scrollTo(0,0);</script>", false);

sorry, no # in URL

this.Page.MaintainScrollPositionOnPostBack = false;
gave the same result.

I also tried setting MaintainScrollPositionOnPostBack  in the aspx @page directive but no difference
I have the same issue.  It's as tho the postback is telling the app to go back to the same position, no matter how I try to override.  I've tried it at the 'onValueChanged' of a hiddenfield.  (The page number) which seems reasonable, but always end up at the same spot.
I havn't solved this yet so if you do, please let me know.
thanks
ASKER CERTIFIED SOLUTION
Avatar of prairiedog
prairiedog
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial