[Last Call] Learn how to a build a cloud-first strategyRegister Now


ASP.NET - How do I autoscroll to the TOP of a user control upon postback?

Posted on 2005-05-06
Medium Priority
Last Modified: 2008-02-01
I know how to retain the relative page position, upon form submit, and autoscroll to that position upon postback (using javascript, not smartnavigation).

However, instead of retaining a specific position (for instance, in the middle of a long datagrid) I would like it to auto scroll to the top of the specific user control.

Does anyone know how to do this?  Thanks in advance!
Question by:mannymartins
  • 4
  • 2
LVL 35

Expert Comment

ID: 13946950
Could you use a html anchor in the page?  Or is that not what you are asking?

Author Comment

ID: 13946983
well, if there's a way to autoscroll to a specified anchor upon postback, then i'd accept that.

the question would then become, how do i tell the browser to scroll to the anchor upon postback, after all, it's not the same as a redirect with the "#anchorname" in URL.

Author Comment

ID: 14019085
hmm.. no replies in over a week.  does this mean it's just not possible, or too difficult to do?
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

LVL 35

Accepted Solution

mrichmon earned 375 total points
ID: 14019825
Sorry didn't get the first email that you had replied.

What about having it so that on postback you add the following javascript to the page that gets executed onLoad:

location.hash = 'myAnchor';

Then have an anchor at the point you want to jump to.

Author Comment

ID: 14020897
yeah, i'm trying something like that now, but i haven't figured out how to register a script block to the page from within a usercontrol yet.  thanks for the reply!

Author Comment

ID: 14021001
Ugh, why am I not thinking today... For whatever reason, I was trying "this.RegisterClientScriptBlock", where I should have been using "Page.RegisterClientScriptBlock".

Anyhow, a form of your idea is working partway now.  Specifically, I'm registering the following block to the page upon firing a command from the datagrid:
   <script language="JavaScript">

And for "pageanchor" I'm using the ID of the usercontrol.

mrichmon, you get the points since your answer closely resembles what works for me.  :)

Featured Post

Upgrade your Question Security!

Add Premium security features to your question to ensure its privacy or anonymity. Learn more about your ability to control Question Security today.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

CTAs encourage people to do something specific to show interest in your company, product or service. Keep reading to learn why CTAs should always be thought of as extremely important, albeit small, sections of websites.
Strategic internal linking is often considered an SEO power technique, especially for content marketing. Do you need to hire an SEO agency to optimize you internal linking? No, this article will help you understand the basics of internal linking and…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Any person in technology especially those working for big companies should at least know about the basics of web accessibility. Believe it or not there are even laws in place that require businesses to provide such means for the disabled and aging p…
Suggested Courses
Course of the Month17 days, 23 hours left to enroll

830 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question