This is a migrated thread and some comments may be shown as answers.

[Solved] Keeping Focus after AJAX request

1 Answer 370 Views
Ajax
This is a migrated thread and some comments may be shown as answers.
instigator
Top achievements
Rank 1
instigator asked on 24 Apr 2009, 02:52 PM
I hate it when an item in a form makes an ajax request and then I lose focus where I was at in the form. Here is the RadAjax solution I came up with to solve this problem. There's probably 100 solutions to this, but here's what I did.


In the Page_Load I check to see if there was an ajax request, and if there was, set the focus. "radAjaxManager" is the ID of my RadAjaxManager control.

//Maintain cursor position on ajax postback
var rad = RadScriptManager.GetCurrent(this.Page);
string ajaxTrigger = rad.AsyncPostBackSourceElementID;
Control c = rad.FindControl(ajaxTrigger);

if (c != null)
{
   if (!string.IsNullOrEmpty(ajaxTrigger) && !ajaxTrigger.Contains("radAjaxManager"))
   {
      radAjaxManager.FocusControl(c.ClientID);
   }
}


1 Answer, 1 is accepted

Sort by
0
Iana Tsolova
Telerik team
answered on 27 Apr 2009, 09:44 AM
Hi instigator,

Thank you for sharing your solution with the community.

Another way to focus control after an AJAX request is to use the FocusControl() method of RadAjax as shown here.

Sincerely yours,
Iana
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
Tags
Ajax
Asked by
instigator
Top achievements
Rank 1
Answers by
Iana Tsolova
Telerik team
Share this question
or