Monday, April 7, 2008

Reset all control values in .NET Web pages.

private void ResetFields()
{

foreach (Control ctrl in this.Controls)

{if (ctrl is TextBox)

{

TextBox tb = (TextBox)ctrl;

if (tb != null)

{ tb.Text = string.Empty;

}

} else

if (ctrl is DropDownList)

{ DropDownList dd = (DropDownList)ctrl;

if (dd != null)

{

dd.SelectedIndex = 0;

}

}

}