This is a migrated thread and some comments may be shown as answers.

FindControl Problem

1 Answer 64 Views
Dock
This is a migrated thread and some comments may be shown as answers.
Zaheer
Top achievements
Rank 1
Zaheer asked on 05 Apr 2012, 10:49 AM
I am Using two ascx files in one aspx file
a.ascx
    raddock1
    raddock2
b.ascx
    raddock3
    raddock4

main aspx
radzone 1
radzone2

i want to display raddock1 in radzone2 of aspx
but when i use findcontrol it will return me null

 

1 Answer, 1 is accepted

Sort by
0
Zaheer
Top achievements
Rank 1
answered on 06 Apr 2012, 06:43 AM

 

 

This function resolve my problem

private
Control FindControlRecursive(Control rootControl, string controlID)

 

{

 

 

if (rootControl.ID == controlID) return rootControl;

 

 

 

foreach (Control controlToSearch in rootControl.Controls)

 

{

 

 

 

Control controlToReturn =

 

 

FindControlRecursive(controlToSearch, controlID);

 

 

 

if (controlToReturn != null) return controlToReturn;

 

 

}

 

 

 

return null;

 

}

Tags
Dock
Asked by
Zaheer
Top achievements
Rank 1
Answers by
Zaheer
Top achievements
Rank 1
Share this question
or