清空文本框,如TextBox、<input type="text" />,等等。
主要是對給定的控件進(jìn)行遍歷,如果控件包含子控件,遞歸,否則判斷控件是否為文本框,并作相應(yīng)的處理,如:給控件屬性Text(TextBox)或者value(<input type="text" />)賦上空值。
///<summary>
/// 清空文本框
///</summary>
///<param name="controls"></param>
publicvoid EmptyTextBox(ControlCollection controls)
{
foreach (Control c in controls)
{
if (c.Controls.Count >0)
{
// 遞歸
this.EmptyTextBox(c.Controls);
}
elseif (c is TextBox)
{
// 服務(wù)器控件
((TextBox)c).Text ="";
}
elseif (c is HtmlInputText)
{
// HTML 控件
((HtmlInputText)c).Value ="";
}
}
}
簡單示例
this.EmptyTextBox(this.form1.Controls);