I'm trying to create a control (MyControl
) which does things to other controls on the page it's on. It has a property:
public property System.Web.UI.Control SomeOtherControl;
I want to be able to set this property from the ASPX page that uses the control. Right now, the only way I can do it is in the Page_Load
of the code-behind:
MyControl.SomeOtherControl = TheOtherControl;
Instead of having to do this on the code-behind of every page that uses MyControl
, I want do just do this on the ASPX page:
<xyz:MyControl SomeOtherControl="TheOtherControlsID" />
In order to do this I tried using the Page.FindControl()
method on the ID string to find the referenced control when MyControl
initializes, but it only searches the page's top-level controls. I could write my own recursive FindControl()
, but I figure there must be a better way to do this, and I'm worried about the performance of something like that. Any ideas?