tags:

views:

218

answers:

5

I have a form that when submitted successfully generates new elements on the page describing the successful form submission and providing the user with some "next steps" information.

This success message element is at the top of the page and I'd like to bring the user's scroll position to this point after they submit the form.

I understand there are a variety of implementation options, and everything I can think of feels like a hack. Any clean and efficient suggestions? Best practices?

A: 

if you are doing an ajax post then you can use something like jQuerys scrollTo to move the page to a specific position.

see here for demo: http://demos.flesler.com/jquery/scrollTo/

Josh

Josh
+1  A: 

Why not use AJAX?

There would be no form submission, the user hasn't left their position on the page, but you can use javascript to insert a message to the user anywhere in the DOM.

This is basically what I'm starting out with already. The user's position on the page doesn't change (even with the post back), which is undesirable as I can't guarantee that this person will be in a position to see the success message, as they could be in the middle of the form still and the top of it is not viewable, depending on their resolution.
Ian Robinson
A: 

Use Javascript to add a named anchor on the page at the point you want to scroll to, then use another javascript snippet to navigate to that anchor.

It's not pretty, but it's the most simple.

Justin Niessner
A: 

Try the following:

if (Page.IsValid)
    Page.MaintainScrollPositionOnPostBack = false;

I believe this property is true by default, which causes the page to remember its current scroll position on postback. If you turn it off in code behind, the postback should send you back to the top of the page.

A: 

You can use the SetFocus() methods to set focus to a particular control. However, this probably won't work if your calling code is within an update panel.

Dan Diplo