hi

I'm creating a UserControl, I want to set a property like TargetDropDownID which is supposed to be a "string" type of data. Not a DropDownList Control so that i can set this property in html view.

OK the Find Control doesn't help in this regard because the whoever will use my UserControl will not be able to tell what is the container of that DropDownList as FindControl seems to have the Container ... like Page.FindControl will search only ONE level search on "Page" object.

Now is there anyway that i can loop through ALL the Page and its Children until i find a specific DropDownList Control by its Id in string.

Ok i found this method in asp.net forums like

1    private Control FindControlRecursive(Control root, string id) 
2    { 
3        if (root.ID == id)
4        { 
5            return root; 
6        } 
7    
8        foreach (Control c in root.Controls) 
9        { 
10           Control t = FindControlRecursive(c, id); 
11           if (t != null) 
12           { 
13               return t; 
14           } 
15       } 
16   
17       return null; 
18   }

But Frankly it thrown an error on very first usage

Multiple controls with the same ID 'Image1' were found. FindControl requires that controls have unique IDs.

Can anybody help me?

I'm wondering how AJAX controls work we just set TargetControlID in some extenders and the Extenders Find their control everytime ... HOW ? is this only specific for Microsoft Team?

I'm primarily a vb.net developer, but this line looks strange to me:

private Control FindControlRecursive(Control root, string id)

I'd think you'd need to change the word Control to function. What error are you getting? How are you calling the function?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.