Reputation: 16944
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?
Upvotes: 1
Views: 1442
Reputation: 25339
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.
Upvotes: 0
Reputation: 553
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.
Upvotes: 0
Reputation: 245429
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.
Upvotes: 0
Reputation:
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.
Upvotes: 1
Reputation: 6322
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
Upvotes: 0