"Paul D. Fox" <pd*****@rcn.com> wrote in message
news:eP**************@tk2msftngp13.phx.gbl...
I want to be able to loop through all the TextBoxes on a page and clear
their values. How can I write a function to do that?
C#:
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);
}
}
}
VB.Net:
Public Sub ClearTextBoxes(ByVal Parent As WebControl)
For Each child As WebControl In Parent.Controls
If GetType(child) Is TextBox
DirectCast(child, TextBox).Text = String.Empty
ElseIf GetType(child) Is IContainer
ClearTextBoxes(child)
End If
Next
End Sub
Off the top of my head....also, I believe it's IContainer that the second if
needs to check. If not, it needs to be the interface that exposes the
"Controls" collection.
HTH,
Mythran