Search code examples
asp.netfocusmaintainscrollpositionon

ASP.NET Focus Scrolls Page to Input


I have a few textboxes/labels inside of an UpdatePanel. When I tab out of one of the textboxes, a label has to be updated with some text. This causes focus on the page to reset to the topmost element.

This is a data-entry form and the users expect to not have to use the mouse at all. I can set focus back on the correct textbox in code:

Page.SetFocus(tbxInput);

or

tbxInput.Focus();

In IE, the browser scroll position is maintained (woo hoo!). In Chrome and Firefox it is not; the scroll location is adjusted so that the focused textbox is the last element shown on the page. This is really disturbing to the user.

I am using the following rules in my web.config:

<pages theme="Default" styleSheetTheme="Default" maintainScrollPositionOnPostBack="true" validateRequest="false">

How can I achieve the behavior that IE has?


Solution

  • For this kind of thing I update the label text from javascript (possibly using an AJAX call to a web service or page method).