foreach (Control c in control.Controls) is choking on the "in"
I have been trying to get c# code behind for an asp.net web app to simply clear text boxes and people have given me good snippits like:
protected void ClearTextBoxes(Control control)
{
foreach (Control c in control.Controls)
{
if (c is TextBox)
((TextBox)c).Text = "";
if (c is CheckBox)
((CheckBox)c).Checked = false;
}
}
...but in all of them, this and similair snippets like ...
public void ClearTextBoxes(WebControl Parent)
{
foreach (WebControl child in Parent.Controls)
{
if (typeof(child) is TextBox)
{
((TextBox)child).Text = String.Empty;
}
else if (typeof(child) is IContainer)
{
ClearTextBoxes(child);
}
}
}
...my debugger hits the key word "in" and steps over the code in the foreach. AnyOne know why?
I have been trying to get c# code behind for an asp.net web app to simply clear text boxes and people have given me good snippits like:
protected void ClearTextBoxes(Control control)
{
foreach (Control c in control.Controls)
{
if (c is TextBox)
((TextBox)c).Text = "";
if (c is CheckBox)
((CheckBox)c).Checked = false;
}
}
...but in all of them, this and similair snippets like ...
public void ClearTextBoxes(WebControl Parent)
{
foreach (WebControl child in Parent.Controls)
{
if (typeof(child) is TextBox)
{
((TextBox)child).Text = String.Empty;
}
else if (typeof(child) is IContainer)
{
ClearTextBoxes(child);
}
}
}
...my debugger hits the key word "in" and steps over the code in the foreach. AnyOne know why?