ASP.NET Focus Scrolls Page to Input

1.9k Views Asked by At

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?

2

There are 2 best solutions below

3
On BEST ANSWER

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

0
On

Using asp.net AJAX UpdatePanel is an option. Also which version of .net framework are you using.

As per this with 4.0 it should work but I haven't tried.