To reset all the textboex es on a webpage
foreach (Control c in this.Controls)
{
if (c is TextBox)
c.Text = string.Empty;
}
hi iam using this code to reset the all text box to empty in windows application but this code is not working in asp.net
please tell me what would be the code to reset all the text boxes on a webpage using asp.net
1 Answer
Know the answer? Post it. Somebody with the same question will find it here.

Amit ChoudharyRank #145 · 15.8K reputationPosted Mar 21, 2010, 9:19 PM EDT
in asp.net the controls have their heirarchy..
if you have your control directly in to form that have attribute runat="server"
then iterate through control using code like this:
foreach (Control c in form1.Controls)
{
if (c is TextBox)
c.Text = string.Empty;
}
But in this case the textbox should not be nested inside another server control.
rest it'll work fine.