This is a migrated thread and some comments may be shown as answers.

Can Textbox show the clear button only when textbox is active?

2 Answers 655 Views
TextBox
This is a migrated thread and some comments may be shown as answers.
Carlos
Top achievements
Rank 1
Carlos asked on 16 Sep 2018, 05:19 AM

I have several textboxes with the option to show clear button enable but I want to shoe the clear button only when a textbox is active by the user. Can this be done?

2 Answers, 1 is accepted

Sort by
0
Dess | Tech Support Engineer, Principal
Telerik team
answered on 17 Sep 2018, 01:30 PM
Hello, Carlos, 
 
By default, the clear button is displayed once the user enters some input. It doesn't matter whether the control is focused or not. The clear button will always be visible if there is some text. 

public RadForm1()
{
    InitializeComponent();
 
    this.radTextBox1.ShowClearButton = true;
 
    this.radTextBox1.GotFocus += radTextBox1_GotFocus;
    this.radTextBox1.LostFocus += radTextBox1_LostFocus;
}
 
private void radTextBox1_LostFocus(object sender, EventArgs e)
{
    this.radTextBox1.ShowClearButton = false;
}
 
private void radTextBox1_GotFocus(object sender, EventArgs e)
{
    this.radTextBox1.ShowClearButton = true;
}

If you need to show the clear button only when the control is focused, you can use the following code snippet:
 
 
I hope this information helps. If you need any further assistance please don't hesitate to contact me. 

Regards,
Dess
Progress Telerik
Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
0
Carlos
Top achievements
Rank 1
answered on 17 Sep 2018, 02:08 PM

Thank you

It worked like a charm!

Tags
TextBox
Asked by
Carlos
Top achievements
Rank 1
Answers by
Dess | Tech Support Engineer, Principal
Telerik team
Carlos
Top achievements
Rank 1
Share this question
or