foreach( Control childControl in this.Controls ) { if( childControl is TextBox ) ((TextBox)childControl).Text = ""; } }
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=""; } } } }
用下面的方法可以: protected void ClearBox() { ControlCollection ss = Form.Controls; for (int i = 0; i < ss.Count; i++) { if (ss[i].GetType() == typeof(TextBox)) { ((TextBox)ss[i]).Text = "ss"; } } }
using System; using System.Data; using System.Configuration; using System.Collections; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Web.UI.HtmlControls;public partial class NET_Default5 : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { } protected void Button1_Click(object sender, EventArgs e) { foreach (Control c in this.FindControl("form1").Controls) { if (c is TextBox) { ((TextBox)c).Text = ""; } } } }
{
if( childControl is TextBox )
((TextBox)childControl).Text = "";
}
}
{
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="";
}
}
}
}
{
ControlCollection ss = Form.Controls;
for (int i = 0; i < ss.Count; i++)
{
if (ss[i].GetType() == typeof(TextBox))
{
((TextBox)ss[i]).Text = "ss";
}
}
}
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;public partial class NET_Default5 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
foreach (Control c in this.FindControl("form1").Controls)
{
if (c is TextBox)
{
((TextBox)c).Text = "";
}
} }
}