Previous Topic: Closing DialogsNext Topic: Modal and Modeless Dialogs


Focus Events

Under certain circumstances, GainFocus and LoseFocus events act slightly different in ASP.NET than they do in Web Generation and GUI clients because of architecture differences in these environments. Without this behavior difference, ASP.NET applications could go into an infinite loop.

For example, if the First Control on a page has GainFocus and LoseFocus events associated with it and the mouse is clicked where no other control on the page acquires focus, such as on the window where no other control resides, or on the Address Box in browser, the LoseFocus event fires for the control. When the page redraws, focus is back on the First Control. A GainFocus event does not fire because the First Control had focus and is the next control to acquire focus.

If another mouse click occurs, the LoseFocus event fails to occur since it would be a duplicate event because LoseFocus was the last processed event. In this case, if the mouse clicked is in the Address Box, the focus stays in the Address Box because the event processing was never sent to the server, and there would be no reason to redraw the window and reset focus to the First Control.