Q2 2010 and later
3.5 or later
|Visual Studio version
2008 or later
all browsers supported by RadControls
Often rich client web applications are required to simulate user experience close to WinForms applications. One such requirement is that focus is preserved on the last focused input when an AJAX postback occurs. Although essential for providing seamless user experience, preserving the focus most of the time involves tedious, hacky and unstable coding approaches that are custom tailored to fit the individual scenario.
This code library demonstrates a small client AJAX component that facilitates the common task of preserving focus after AJAX postbacks and tries to be generic enough to be applicable to a large set of business scenarios. The FocusPersister
The FocusPersister handles the usual scenario of saving the last focused input's ID before an AJAX request and restoring focus to the newly refreshed input with the same ID after the AJAX content is updated. It can be configured to exclude buttons and links from tracking (they get the focus when clicked, which may not always be desired). Additionally, you can specify the type of selection that should be applied to the input that is re-focused after AJAX: caret should be at the beginning of the input text, at the end, all the text should be selected on focus, or no specific logic should be applied (defaulting to the browser's default behavior).
A sample test project demonstrating the FocusPersister is attached. It can work with either regular ASP.NET TextBox controls, or any of the Telerik RadInput controls (RadTextBox
) plus RadComboBox
, and supports AJAX scenarios with UpdatePanels, RadAjaxPanels