How to clear more than one textboxes values when button is clicked. [Resolved]

Posted by Srinibaschampati under C# on 8/14/2013 | Points: 10 | Views : 1776 | Status : [Member] | Replies : 2
How to clear more than one textboxes values when button is clicked.




Responses

Posted by: Bandi on: 8/14/2013 [Member] [MVP] Platinum | Points: 25

Up
0
Down
protected void Button2_Click(object sender, EventArgs e)

{
ClearInputs(Page.Controls);
}
void ClearInputs(ControlCollection ctrls)
{
foreach (Control ctrl in ctrls)
{
if (ctrl is TextBox)
((TextBox)ctrl).Text = string.Empty;
ClearInputs(ctrl.Controls);
}
}


Mark This Response as Answer
--
Chandu
http://www.dotnetfunda.com/images/dnfmvp.gif

Srinibaschampati, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Akshayyy on: 8/14/2013 [Member] Starter | Points: 25

Up
0
Down
Hi,
U can easily do so by writing a Clear method and calling this method on the button click.
for eg:
private void Clear()
{
textbox1.text = string.Empty;
textbox2.text = string.Empty;
textbox3.text = string.Empty;
...
....
}

Like wise u can clear the text of as many text boxes that are present on the page.
Hope this Helps.

Srinibaschampati, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response