By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
428,785 Members | 2,074 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 428,785 IT Pros & Developers. It's quick & easy.

asp.net how do you find the TextBox that had focus when the post happened

P: 1
Is there a way to know which control had focus when the post in the browser happened ?

Thank you in advance.
Dec 15 '08 #1
Share this Question
Share on Google+
3 Replies


Frinavale
Expert Mod 5K+
P: 9,731
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.
Dec 16 '08 #2

10K+
P: 13,264
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.
Dec 17 '08 #3

balabaster
Expert 100+
P: 797
@r035198x
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.
Dec 17 '08 #4

Post your reply

Sign in to post your reply or Sign up for a free account.