Hi there guys I just want to know how I can create a reset button that will erase all the contents written by a user in textboxes? I am creating an Enrollment Form for Students and I need some help about it. I have attached a screenshot for you guys be sure to check it. Thanks in advance!

Recommended Answers

All 7 Replies

Just set the Text property to string.Empty or to whatever they contained initially in the Click event handler of your reset button.

Just set the Text property to string.Empty or to whatever they contained initially in the Click event handler of your reset button.

sir can you show me a sample code on how to do it? thanks!

MyTextBox1.Text = string.Empty;
MyTextBox2.Text = string.Empty;
// etc.
MyTextBox1.Text = string.Empty;
MyTextBox2.Text = string.Empty;
// etc.

theres another way of doing this:

textbox1.Clear();

thank you sir!

Respect to above question MytextBox1.text = string.Empty; will only work for a single instance what if i want to clear my all textbox at a single instance.

Would be better to start a new thread.

By a single instance do you mean like one line or in one method?

you could use a foreach loop to clear all textboxes within a parent control.

foreach(Control Control in Form1.Controls)
{
    if(Control is textBox)
    {
        (Control as textBox).Clear();
    }
}

If you group together the textbox in a panel/groupbox, pass in the parent control to the loop.

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.