Ajax Problem: UpdatePanel with dropdownlist jumps to bottom of the page

R

retroman80s

I have an UpdatePanel with a DropDownList. Everytime I select a new
item on the DropDownList, the UpdatePanel refreshes and the page jumps
to the bottom. I want it to go back to the top of the page, any ideas
what the problem is?


Everything ASP.NET 2.0
 
K

Kevin

Yep, by default ASP.NET AJAX retains the current document scroll
position (which is a good thing since 95% of the time end users would
want that). In your case, you can wire the endRequest event of the
AJAX request and scroll to top using something similar to:

<asp:ScriptManager ID="ScriptManager1" runat="server"
EnablePartialRendering="true"/>

<script type="text/javascript">


var prm = Sys.WebForms.PageRequestManager.getInstance();
prm.add_endRequest(OnEndRequest);

function OnEndRequest(sender,args)
{
window.scrollTo(0,0);
}
</script>

Just make sure the javascritp code is below ScriptManager tag
(otherwise a javascript not defined error will occur)
 
R

retroman80s

Yep, by default ASP.NET AJAX retains the current document scroll
position (which is a good thing since 95% of the time end users would
want that). In your case, you can wire the endRequest event of the
AJAX request and scroll to top using something similar to:

<asp:ScriptManager ID="ScriptManager1" runat="server"
EnablePartialRendering="true"/>

<script type="text/javascript">

var prm = Sys.WebForms.PageRequestManager.getInstance();
prm.add_endRequest(OnEndRequest);

function OnEndRequest(sender,args)
{
window.scrollTo(0,0);
}
</script>

Just make sure the javascritp code is below ScriptManager tag
(otherwise a javascript not defined error will occur)


Thanks Kevin for replying. It work great in IE, but in firefox the
first time you try it, it still jumps to the bottom of the page. The
funny thing is that the second and other times you try it, it works.
Any ideas why it doesn't go to the top the first time the page loads?

Thanks

Everything ASP.NET 2.0
 

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,769
Messages
2,569,577
Members
45,052
Latest member
LucyCarper

Latest Threads

Top