2

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?

Harper
  • 1,285
  • 3
  • 15
  • 35

2 Answers2

1

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

tster
  • 17,883
  • 5
  • 53
  • 72
  • Is there a way to bypass this situation by somehow keeping the focus from resetting when the label's text is updated? It seems overkill to have to do this :[ – Harper Dec 20 '10 at 20:42
  • @Harper did you ever find an answer to your comment? – Tristan Descartes Oct 16 '13 at 22:17
  • @Tristan Descartes, my solution (updating the label in javascript) does avoid losing the focus. The problem the OP is running in to is that his UpdatePanel is doing a postback and getting updated by code behind. However, my solution is pure javascript, causes no postback, and leaves the focus completely untouched. You can even use AJAX within your javascript if you need to get some values from the server. – tster Oct 21 '13 at 22:20
0

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.

gbs
  • 7,196
  • 5
  • 43
  • 69