Let say i hv two textbox, i.e. TextBox1 and TextBox2 and a button. Is it possible for me to write text into either Textbox1 or TextBox2 when the focus is at the textbox and button is clicked subsequently?

For example my focus is now at TextBox1 then i clicked on the button. TextBox1 is filled with "abc".

Is it possible for me to do that?

Recommended Answers

All 4 Replies

Even if the focus is in TextBox1, after clicking the button, the focus moves to the button(TextBox1 will lose the focus). Therefore write code for the onclick event of the button to fill 'abc' to TextBox1 and set the focus again to the TextBox1.

I think you could use javascript to 'record' the last focused textbox and grab that information client side and populate the textBox. If you're wanting the button to populate the text on a server side postback then you could use a hidden form field to pass back the last focused text box.

If this is the case, how do i determine the last focus with C#?

You don't. You need to find some javascript code that does this. You're wanting to know client-side focus and C# is server-side language.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.