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

How to empty textbox.text after event?

1 Answer 22 Views
TextBox
This is a migrated thread and some comments may be shown as answers.
ZHOU
Top achievements
Rank 2
ZHOU asked on 27 Aug 2014, 03:24 PM
I was trying to empty those textbox text after the event
Thats what i have now:
                           
 foreach (Control ctrl in this.Controls)
  {
         RadControl rc = ctrl as RadControl;
                                
         if (rc is TextBox)
           {
                rc.Text = "";
           }
 
  }

Any help will be appreciated , thanks

1 Answer, 1 is accepted

Sort by
0
Dess | Tech Support Engineer, Principal
Telerik team
answered on 01 Sep 2014, 11:27 AM
Hello Zhou,

Thank you for writing.

I am not sure what exactly is the specific case, but following your sample code I noticed that you are trying to cast a RadControl to MS TextBox instance, which is not supposed to succeed. In order to clear the text from all RadTextBox controls, you must cast to RadTextBox:
private void radButton1_Click(object sender, EventArgs e)
{
    foreach (Control ctrl in this.Controls)
    {
        RadControl rc = ctrl as RadControl;
                         
        if (rc is RadTextBox)
        {
            rc.Text = "";
        }
    }
}

I hope this information helps. Should you have further questions, I would be glad to help.

Regards,
Desislava
Telerik
 
Check out Telerik Analytics, the service which allows developers to discover app usage patterns, analyze user data, log exceptions, solve problems and profile application performance at run time. Watch the videos and start improving your app based on facts, not hunches.
 
Tags
TextBox
Asked by
ZHOU
Top achievements
Rank 2
Answers by
Dess | Tech Support Engineer, Principal
Telerik team
Share this question
or