Empty multiple textbox at once

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.