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
Amit ChoudharyPosted Mar 22, 2010, 1:19 AM
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.