请编程遍历页面上所有TextBox控件并给它赋值为string.Empty?
我做的时候分了2中情况:一种是窗体控件,另一种是web控件。
窗体控件:
View Code
foreach (System.Windows.Forms.Control aa in this.Controls)
{
if (aa is System.Windows.Forms.TextBox)
{
System.Windows.Forms.TextBox ss = (System.Windows.Forms.TextBox)aa;
ss.Text = String.Empty;
}
}
Web控件:
View Code
foreach (System.Web.UI.Control aa in this.FindControl("form1").Controls)
{
if (aa is System.Web.UI.WebControls.TextBox)
{
System.Web.UI.WebControls.TextBox ss = (System.Web.UI.WebControls.TextBox)aa;
ss.Text = String.Empty;
}
}