I have a web application that is using a RadAjaxManager to update some sections of the page automatically after the page loads - for performance so I can load the main content right away and additional content a couple seconds later. However, I noticed that after the ajax call returns the browser window scrolls to near the top of the page. This creates a disorienting user experience, especially if the user has scrolled down a little ways before the ajax call returns.
I created a sample application to demonstrate this issue.
Here is the aspx code:
The code behind:
This page has two buttons on it that do ajax posts and sleep for 5 seconds. When you click on either one, immediately scroll down the page. Once the ajax call returns, the browser window returns to the top of the page. Is there a way to prevent this?
I created a sample application to demonstrate this issue.
Here is the aspx code:
| <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="TelerikTest._Default" %> |
| <%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %> |
| <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> |
| <html xmlns="http://www.w3.org/1999/xhtml" > |
| <head runat="server"> |
| <title>Untitled Page</title> |
| </head> |
| <body> |
| <form id="form1" runat="server"> |
| <telerik:RadScriptManager ID="scriptManager" runat="server"></telerik:RadScriptManager> |
| <telerik:RadAjaxManager ID="ajaxManager" runat="server"> |
| <AjaxSettings> |
| <telerik:AjaxSetting AjaxControlID="divRight"> |
| <UpdatedControls> |
| <telerik:AjaxUpdatedControl ControlID="divRight" /> |
| </UpdatedControls> |
| </telerik:AjaxSetting> |
| <telerik:AjaxSetting AjaxControlID="divLeft"> |
| <UpdatedControls> |
| <telerik:AjaxUpdatedControl ControlID="divLeft" /> |
| </UpdatedControls> |
| </telerik:AjaxSetting> |
| </AjaxSettings> |
| </telerik:RadAjaxManager> |
| <div> |
| <table> |
| <tr> |
| <td> |
| <div id="divLeft" runat="server" style="height:2000px; width:400px; border:solid 1px black;"> |
| <asp:Button ID="btn1" runat="server" Text="Post Back" onclick="btn_Click" /> |
| </div> |
| </td> |
| <td> |
| <div id="divRight" runat="server" style="height:200px; width:400px; border:solid 1px black;"> |
| <asp:Button ID="btn2" runat="server" Text="Post Back" onclick="btn_Click" /> |
| </div> |
| <div style="height:1800px; width:400px; border:solid 1px blue;"></div> |
| </td> |
| </tr> |
| </table> |
| </div> |
| </form> |
| </body> |
| </html> |
The code behind:
| using System; |
| using System.Collections; |
| using System.Configuration; |
| using System.Data; |
| using System.Web; |
| using System.Web.Security; |
| using System.Web.UI; |
| using System.Web.UI.HtmlControls; |
| using System.Web.UI.WebControls; |
| using System.Web.UI.WebControls.WebParts; |
| namespace TelerikTest |
| { |
| public partial class _Default : System.Web.UI.Page |
| { |
| protected void Page_Load(object sender, EventArgs e) |
| { |
| } |
| protected void btn_Click(object sender, EventArgs e) |
| { |
| System.Threading.Thread.Sleep(5000); |
| } |
| } |
| } |
This page has two buttons on it that do ajax posts and sleep for 5 seconds. When you click on either one, immediately scroll down the page. Once the ajax call returns, the browser window returns to the top of the page. Is there a way to prevent this?
