Method 1:
foreach( Control childControl in this.Controls )
{
if( childControl is TextBox )
((TextBox)childControl).Text = "";
}
}
Method 2:
用反射:
FieldInfo[] infos = GetType().GetFields( BindingFlags.Public | BindingFlags.NonPublic|BindingFlags.GetField |BindingFlags.Instance);
for(int i=0;i<infos.Length;i++)
{
if(infos[i].FieldType == typeof(TextBox))
{
((TextBox)infos[i].GetValue(this)).Text = "";
}
}
Method 3:
使用js,好处是不用刷新页面:
function ClearAllTextBox()
{
var obj=window.document.forms[0];
for(i=0;i<obj.elements.length; i++)
{
var elem=obj.elements[i];
if(elem)
{
if(elem.type=="text")
{
elem.value="";
}
}
}
}