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

Posted on 2005-05-06
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
    LVL 35

    Expert Comment

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

    Author Comment

    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

    hmm.. no replies in over a week.  does this mean it's just not possible, or too difficult to do?
    LVL 35

    Accepted Solution

    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

    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

    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

    Top 6 Sources for Identifying Threat Actor TTPs

    Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

    Join & Write a Comment

    Accessibility and Usability are two concepts that seem to be closely related.  But, too many people seem to have a distorted perception of them. During last five years, those two words have come to the day-to-day work of almost every web develope…
    Envision that you are chipping away at another e-business site with a team of pundit developers and designers. Everything seems, by all accounts, to be going easily.
    This tutorial walks through the best practices in adding a local business to Google Maps including how to properly search for duplicates, marker placement, and inputing business details. Login to your Google Account, then search for "Google Mapmaker…
    The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

    728 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

    Need Help in Real-Time?

    Connect with top rated Experts

    18 Experts available now in Live!

    Get 1:1 Help Now