Problem with RadTextBox.Focused in Telerik 2010Q1

6 posts, 1 answers
  1. Gabriele Svelto
    Gabriele Svelto avatar
    6 posts
    Member since:
    Sep 2009

    Posted 03 May 2010 Link to this post

    I have a piece of code that refreshes a RadTextBox Text property depending on external events. In order not to change the Text property while the user is typing in the text box I check the Focused property first and proceed in overwriting the Text property only if it is false, the relevant code looks like this:

    private void event_ExternalUpdate(object sender, EventArgs args) 
        if (!textBox.Focused) 
            textBox.Text = "foo"

    However in Telerik 2010Q1 this does not seem to work. I have tried to check at runtime and apparently the Focused property is always false even though I am editing that particular text-box. I have made a super-simplified test case and tried it with both Telerik 2009Q3 and 2010Q1 and it works correctly under version 2009Q3 (Focused is set to true when I'm typing in the field) but not on 2010Q1. Is this a bug or is there another way to check if a specific control has the input focus?

    As a temporary workaround I noticed that the FocusedElement property is null when the text-box doesn't have the input focus and points to the embedded RadTextBoxItem when it has focus so I'm using it instead. However because FocusedElement is not documented I am a bit wary of using it.
  2. Jason Maronge
    Jason Maronge avatar
    321 posts
    Member since:
    Jan 2005

    Posted 05 May 2010 Link to this post

    I am having a similar issue.  No matter what I do I can't get the RadTextBox to focus in code.

    Here is what I am trying to do:

            public void SetFocus() 
                ActiveControl = txtCode; 

    You would think that one of those calls would set focus to the control.  Something is broken with the focus

  3. Answer
    Deyan avatar
    2147 posts

    Posted 06 May 2010 Link to this post

    Hi Gabriele and Jason,

    As of Q1 2010 we introduced some changes in the way the RadTextBox control handles the focus. Since there were certain issues with the GotFocus and LostFocus events, as well as the Focus method, we decided to revisit the logic and improve it. The RadTextBox control hosts a standard TextBox control and extends its functionality by providing support for the Telerik Presentation Framework (theming, dependency properties etc.). Since the control itself is not the focused control (but the TextBox inside) the Focused property will not be set to true. However, you can use the ContainsFocus property. This property will always be true when a control inside the current control is focused. Take a look at the following code snippet:

    void radTextBox1_TextChanged(object sender, EventArgs e)
        if (this.radTextBox1.ContainsFocus)

    As for the Focus method, I tried to reproduce the issue with calling it and not getting the control focused but to no avail. The Focus method works as expected for me:


    This correctly puts the focus into the control.

    Jason, could you please share with me further details on your scenario so that I can make sure that I correctly try to reproduce the issue?

    Best wishes,
    the Telerik team

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
  4. Gabriele Svelto
    Gabriele Svelto avatar
    6 posts
    Member since:
    Sep 2009

    Posted 06 May 2010 Link to this post

    Thank you Deyan, ContainsFocus was exactly what I was looking for.
  5. Niska
    Niska avatar
    7 posts
    Member since:
    Feb 2012

    Posted 15 Feb 2012 Link to this post


    I'm working from the aspx page - client side,
    and the 'ContainsFocus' is undefined

    is there any other function for me?

  6. Nikolay
    Nikolay avatar
    1805 posts

    Posted 15 Feb 2012 Link to this post

    Hi Niska,

    Please note that this thread concerns RadControls for WinForms. If your question is about our ASP.NET suite, please address it in the appropriate forum section.

    the Telerik team
    Sharpen your .NET Ninja skills! Attend Q1 webinar week and get a chance to win a license! Book your seat now >>
Back to Top