locked
Set focus of an element from its lost focus RRS feed

  • Question

  • For some reason focus a text box is need, so the focus is again set to the text box from its lost focus. This leads to stack over flow in the lost focus event. 

    Say,
     A Textbox and a button, now the focus is in Textbox and clicking on the button. In this case, need the focus to be in the textbox, so focus method of text box is invoked from its lost focus. This leads to stack over flow exception.

    Why this happens and also how do the focus is retained in text box itself.

    Sankar

    Wednesday, July 24, 2013 5:41 AM

Answers

  • Hi

    on button click event

    try somthing like this

    Keyboard.Focus(controlName);

    or

    FocusManager.SetFocusedElement(this, controlName);


    Harshad..... Always 4 U

    Wednesday, July 31, 2013 9:15 AM

All replies

  • Hi ,

    Please have isdefaulted=true in the text box

    Regards,

    Stygen

    Wednesday, July 24, 2013 6:44 AM
  • Hi,

    Cant you write textboxname.focus(), in button click event after completing your logic.

    Thanks,

    Rajnikant

    Wednesday, July 24, 2013 6:47 AM
  • Hi

    U try this using

    Dispatcher.BeginInvoke(() => {textBox.Focus();});


    Kavithaa.N

    Wednesday, July 24, 2013 7:20 AM
  • It will make a loop and leads to stack over flow while setting focus on lost focus..

    Sankar

    Wednesday, July 31, 2013 5:15 AM
  • Hi

    on button click event

    try somthing like this

    Keyboard.Focus(controlName);

    or

    FocusManager.SetFocusedElement(this, controlName);


    Harshad..... Always 4 U

    Wednesday, July 31, 2013 9:15 AM