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!

Attachments hehehe.jpg 15.97 KB

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.

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.

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.

This question has already been answered. Start a new discussion instead.