Foreach ergodic control emptied the contents of textbox, why to run when the inp

 protected void Button2_Click(object sender, EventArgs e)
 {

 for (int i = 0; i <Page.Controls.Count; i++)
 {



 foreach (System.Web.UI.Control b in Page.Controls[i].Controls) 


 {


 if (b is TextBox)
 {
 TextBox tb = (TextBox)b;
 tb.Text ="";

 }

 }

 
 }




 }

Started by Sammy at November 13, 2016 - 3:21 PM

Using for and foreach?
The latter can be.

Posted by Jasmine at November 19, 2016 - 4:19 PM

You probably didn't find what you're looking for TextBox.

So, you don't empty, you give it a set a fixed value (such as DateTime.Now.ToString), have a look you can set? If not provided, you even didn't know how to get.

Posted by Kenneth at December 02, 2016 - 4:40 PM

Control is a level, you just visited the top 2 layer. Recursion looking down.

Posted by Hardy at December 16, 2016 - 5:24 PM

There are many reasons, such as the use of master pages, structure the control tree and your expectations are not the same, for example, button.click events and assign a value to the other place, such as the character and problems, etc.

Posted by Roderick at December 21, 2016 - 5:49 PM

You follow me
if (b is TextBox)
{
TextBox tb = (TextBox)b;
tb.Text ="";

}
To execute the code cannot be. If cannot carry out that you didn't find what you're looking for the TextBox control.

Posted by Franklin at January 01, 2017 - 6:36 PM

private void btnReset_Click(object sender, System.EventArgs e)
		{
			ArrayList lstTxt=this.GetControl(this);
			foreach(object o in lstTxt)
			{
			  ((System.Web.UI.WebControls.TextBox)o).Text="";
			}
						
		}
		private ArrayList GetControl(Control control)
		{
			ArrayList list=new ArrayList();
			foreach(Control con in control.Controls)
			{
				if(con.HasControls())
				{
					ArrayList l=GetControl(con);
					foreach(object o in l)
					{
						list.Add((TextBox)o);
					}
				}
				else
				{
					if(con.GetType()==typeof(System.Web.UI.WebControls.TextBox))
					{
						list.Add(con);
					}
				}
			}
			return list;			
		}

Posted by Pamela at January 03, 2017 - 9:08 PM

Foreach can only do iteration
Cannot modify
In addition you haven't done recursively.
If your TextBlock is placed in a container control within a Panel.
You are unable to traverse to his

Posted by Sheila at January 09, 2017 - 7:31 PM

Agree upstairs, you must use the traversal, it needs to use the recursive, or in the frame or layer control cannot follow up search.

Posted by Leonard at January 11, 2017 - 8:30 PM

+1 or debug run, of course your breakpoint to hit if (B is TextBox) below

Posted by Caspar at January 13, 2017 - 8:33 PM