foreach (Control control in Controls)
{
if(control is TextBox)
{
(control as TextBox).Text="";
}
}
就这样就可以了,没必要写那么麻烦。。
要像LZ写的也可以写成
foreach (System.Web.UI.Control control in this.Page.Form.Controls)
{
if (control is TextBox)
{
(control as TextBox).Text = "";
}
}
System.Web.UI.WebControls control = new System.Web.UI.Control();
这句写错了System.Web.UI.WebControls.TextBox Controls in this.Page.Controls)
------
因为this.Page.Controls里面的对象类型是Control基类,所以你要写System.Web.UI.WebControls.Control
我觉得这种重置页面上textbox的功能可能用JS来做更好