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

jimmieanderssonAsked:
Who is Participating?
 
prairiedogConnect With a Mentor Commented:
You are almost there. Here is what you need:
http://weblogs.asp.net/shenderson/archive/2006/11/29/ajax-how-to-scroll-to-the-top-of-a-page-when-clicking-on-only-the-pager-controls-in-dataview.aspx
Change "ctl00_C1_JobsGridView" in the article to your button's generated ID found in page source.
0
 
Praveen VenuTechnical Project ManagerCommented:
simple.. In the button1_click after all other code execute

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

0
 
jimmieanderssonAuthor Commented:
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.
0
Introducing Cloud Class® training courses

Tech changes fast. You can learn faster. That’s why we’re bringing professional training courses to Experts Exchange. With a subscription, you can access all the Cloud Class® courses to expand your education, prep for certifications, and get top-notch instructions.

 
Praveen VenuTechnical Project ManagerCommented:
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);

0
 
jimmieanderssonAuthor Commented:
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
0
 
jpopowskiCommented:
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.
0
 
jimmieanderssonAuthor Commented:
I havn't solved this yet so if you do, please let me know.
thanks
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.