Link to home
Start Free TrialLog in
Avatar of mannymartins
mannymartins

asked on

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

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!
Avatar of mrichmon
mrichmon

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

ASKER

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.
hmm.. no replies in over a week.  does this mean it's just not possible, or too difficult to do?
ASKER CERTIFIED SOLUTION
Avatar of mrichmon
mrichmon

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
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!
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">
      location.href="#pageanchor";
   </script>

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.  :)