Can someone tell me how to cause the an Ajax postback to return to the top of the page.
In a long display I have button at bottom of page that performs call to Ajax. All works fine, but I want the user to be returned to the top of page. As it is, the user is left at the same screen location after the Ajax call.
I have not tested it, but maybe you could check on the page loading if is a postback, and then execute the javascript window.scrollTo(0,0). Smoething like,
JoeReynolds
Participant
871 Points
313 Posts
Go to top of Page after Ajax postback
Nov 19, 2006 03:53 PM|LINK
Can someone tell me how to cause the an Ajax postback to return to the top of the page.
In a long display I have button at bottom of page that performs call to Ajax. All works fine, but I want the user to be returned to the top of page. As it is, the user is left at the same screen location after the Ajax call.
duditz
Member
14 Points
16 Posts
Re: Go to top of Page after Ajax postback
Nov 19, 2006 05:31 PM|LINK
mritunjay82
Member
5 Points
1 Post
Re: Go to top of Page after Ajax postback
Nov 20, 2006 04:32 AM|LINK
try this. I hope it will work for u as it worked in my case
<
asp:Button ID="btn" runat="server" Text="Add" OnClientClick="javascript:window.scrollTo(0,0);"/>OnClientClick="javascript:window.scrollTo(0,0);"
will take u to top of ur page.
for any desired location change scrollto postions.
JoeReynolds
Participant
871 Points
313 Posts
Re: Go to top of Page after Ajax postback
Nov 20, 2006 01:53 PM|LINK
Manotas
Member
540 Points
131 Posts
Re: Go to top of Page after Ajax postback
Nov 20, 2006 02:06 PM|LINK
I have not tested it, but maybe you could check on the page loading if is a postback, and then execute the javascript window.scrollTo(0,0). Smoething like,
ClientScript.RegisterStartupScript(
Me.GetType, "GoToTop", "<script language=""JavaScript"" > window.scrollTo(0,0) </script>")Manotas
Member
540 Points
131 Posts
Re: Go to top of Page after Ajax postback
Nov 21, 2006 01:24 PM|LINK
However, for unknown reason, the page is going up and then going back to the control began the postback.....
JoeReynolds
Participant
871 Points
313 Posts
Re: Go to top of Page after Ajax postback
Nov 21, 2006 05:17 PM|LINK
Manotas
Member
540 Points
131 Posts
Re: Go to top of Page after Ajax postback
Nov 22, 2006 11:06 AM|LINK
Hi, in another post Omourad gave me this piece of code which works wonderfully and does exactly what you're looking for....
try this, it is working with me:
<% @
Page Language="C#" MasterPageFile="~/MasterPages/Inner.master" AutoEventWireup="true"CodeFile
="Distribute.aspx.cs" Inherits="Distribution_Distribute" %><
asp:ScriptManager runat="server" EnablePartialRendering="True" /><
script type="text/javascript" language="javascript">Sys.WebForms.PageRequestManager.getInstance().add_pageLoaded(pageLoadedHandler)
function
pageLoadedHandler(sender, args){
window.scrollTo(0,0);
}
</script>Cheers,
JoeReynolds
Participant
871 Points
313 Posts
Re: Go to top of Page after Ajax postback
Nov 22, 2006 02:37 PM|LINK
Loisb
Member
3 Points
16 Posts
Re: Go to top of Page after Ajax postback
Apr 09, 2009 04:39 PM|LINK
This worked perfect for me. Thank you.