Click here to Skip to main content
15,935,728 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i want to find all textbox control in one function.
how can i do this and where i have to call that function, in page_load or in any other event??
Posted

1 solution

it will work in asp.net
C#
public partial class _Default : System.Web.UI.Page
   {
      
       public List<TextBox> ListOfTextBoxes = new List<TextBox>();
       protected void Page_Load(object sender, EventArgs e)
       {
           // after execution this line
           FindTextBoxes(Page, ListOfTextBoxes);
           //ListOfTextBoxes will be populated with all text boxes with in the page.

       }


       private void FindTextBoxes(Control Parent, List<TextBox> ListOfTextBoxes)
       {
           foreach (Control c in Parent.Controls) {
               // if c is a parent control like panel
               if (c.HasControls())
               {
                   // search all control inside the panel
                   FindTextBoxes(c, ListOfTextBoxes);
               }
               else {
                   if (c is TextBox)
                   {
                       // if c is type of textbox then put it into the list
                       ListOfTextBoxes.Add(c as TextBox);
                   }
               }
           }
       }
   }
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900