private void Cleartext (ControlCollection Controls)
{
foreach (Control item in Controls)
{
if (item. Controls.Count > 0)
{
Cleartext (item. Controls);
}
If (item is TextBox)
{
(TextBox) Item). Text = "";
}
}
}
There may be more than one container on your page, such as N panel, and a panel with n textbox;
So first you need to get the index container:
foreach (System.Web.UI.Control control in controls)//calendar passes through each control in the container.
Then iterate through all the controls in each container
for (int i = 0; i < control. Controls.Count; i++)//This is the control that traverses all the containers;
Then, in determining whether it is a TextBox control:
if (control. Controls[i] is System.Web.UI.WebControls.TextBox)
Empty multiple textbox at once:
foreach (System.Web.UI.Control Control in Controls)
{
for (int i = 0; i < control. Controls.Count; i++)
{
if (control. Controls[i] is System.Web.UI.WebControls.TextBox)
{
System.Web.UI.WebControls.TextBox TB = (System.Web.UI.WebControls.TextBox) control. Controls[i];
Tb. Text = "";
}
}
}
protected void Page_Load (object sender, EventArgs e)
{
User input
TXTNAME.ATTRIBUTES.ADD ("Value", "Please enter user name");
TXTNAME.ATTRIBUTES.ADD ("onfocus", "if (this.value== ' Enter user name ') {this.value= '}");
TXTNAME.ATTRIBUTES.ADD ("OnBlur", "if (this.value==") {this.value= ' Please enter user name '} ");
Password input
TXTPWD.ATTRIBUTES.ADD ("Value", "Please enter password");
TXTPWD.ATTRIBUTES.ADD ("onfocus", "if (this.value== ' Please enter password ') {this.value= '}");
TXTPWD.ATTRIBUTES.ADD ("OnBlur", "if (this.value==") {this.value= ' Please enter password '} ");
//
if (! IsPostBack)
{
Content
}
}
Empty multiple textbox at once