You'll have to write some JavaScript that keeps track of which field has focus by storing the value in a HiddenField. This HiddenField can then be accessed by the server and you'll know which TextBox had focus last.
Use the TextBox's JavaScript onfocus event to execute the the JavaScript that stores it's client ID in the HiddenField.
I wonder why you'd need that. Most of the time it will be the control that triggered the submit. e.g If a text field has focus, when the submit button is clicked, the submit button will be the one given focus before submitting.
I wonder why you'd need that. Most of the time it will be the control that triggered the submit. e.g If a text field has focus, when the submit button is clicked, the submit button will be the one given focus before submitting.
Doesn't account for AutoPostback. I'm in agreement with Frinny's suggestion:
Write a function that updates a hidden field and add handlers to the OnFocus and OnBlur events to call that function attaching the id of the currently focused object. If you want to know the last focussed object rather than the currently focussed object, then omit the OnBlur event handler.
In the postback check the value of the hidden field.
Comment