Click here to Skip to main content
15,881,803 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
i use this function for find control on page its working fine on button click but not working on page load its return null.

C#
public  Control FindControlRecursive(Control container, string name)
   {
       if (container.ID == name)
           return container;

       foreach (Control ctrl in container.Controls)
       {
           Control foundCtrl = FindControlRecursive(ctrl, name);

           if (foundCtrl != null)
               return foundCtrl;
       }
       return null;
   }



C#
foreach (var result in results)
            {
   TextBox tot = (TextBox)FindControlRecursive(Page, "Total" + i);
   TextBox obtd = (TextBox)FindControlRecursive(Page, "Obtd" + i);
   TextBox pre = (TextBox)FindControlRecursive(Page, "Pre" + i);
   extBox grade = (TextBox)FindControlRecursive(Page, "Grade" + i);
}


What I have tried:

i tried various suggestions from the google.
Posted
Updated 5-Oct-16 17:30pm
v2
Comments
Karthik_Mahalingam 5-Oct-16 1:08am    
is the controls dynamically generated?
raajaakhan 5-Oct-16 4:14am    
yes, on page .aspx file my controls name like this total1,total2,total3,total4 and same like other obtd, pre, grade
Vincent Maverick Durano 7-Oct-16 15:09pm    
How do you generate the controls?

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