Reset scroll position on AJAX postback

M

Mark

Hi.

I have a page which has an update panel covering all of it.

When I do a server postback via the update panel, the screen remains in
the same scroll position - which is ok most of the time.

BUT - if on one of these postbacks within the update panel, I need to
reset the scroll position of the screen to the top - how can I do that?
I've tried .focus() on a control at the top of the page, but this
doesn't work.

Thanks for any guidance,

Mark
 
M

Mark

Hi - just wondering, if the only way to do this would be to not use
AJAX, and just use normal postbacks, which would results in the page
position being reset to 0?

Thanks, Mark
 
Joined
Jun 4, 2009
Messages
1
Reaction score
0
//Client Side Code : Java Script
function ResetScrollPosition()
{
setTimeout("window.scrollTo(0,0)", 0);
}

//Server Side Code : Call above Javascript function :

ScriptManager.RegisterStartupScript(Page, this.GetType(), "ScrollPage", "ResetScrollPosition();", true);

Only,window.scrollTo(0,0) will not work.Ajax will take precedence in this case so you have to use setTimeout function with that.
 
Joined
Aug 18, 2009
Messages
1
Reaction score
0
Thought I'd Let People Know it Worked

Sometimes on threads the person who asked the question gets an answer which does actually work and they're so excited and can get their project completed that they forget to come back and thank the user who provided the solution, plus let everyone else know it works.

I get it and this isn't dumping on the questioner, I totally understand how easy it is to forget to come back. He also could have posted in many different blogs/forums and just never knew it had been answered.

Ok, so to land the darn plane already....the solution provided above with the settimeout does work like a charm! Thanks so much for this solution since it definitely helped me just now.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,017
Latest member
GreenAcreCBDGummiesReview

Latest Threads

Top