views:

47

answers:

2

Hi, I'm making a custom control.

Basically what I'm looking for is a OnPreInit event in custom controls. I basically need to know that all of the controls that will be loaded of type MyCustomControl are constructed or not.

Ok, so basically I need to know in the constructor if the current instance being constructed will be the last.

Note: My custom control contains other controls(though this isn't guaranteed) but it will not contain controls of MyCustomControl class.

I've thought about doing an override of AddParsedObject. But if the instance of my custom control doesn't contain any controls, will this still get called?

A: 

I hate to say use a counter, but you're either going to have to pass state information through a dedicated class (or the context,) which you could do in the constructor of the control prior to testing if you've got as many as you need, or you could do a recursive walk through Page.Controls and their .Controls and test each one for type....

jasondoucette
Well, I tried hooking into Page.OnPreInit. But Page is set to null in the constructor of the custom control, otherwise doing a recursive walk would work as well
Earlz
+2  A: 

Unfortunately the approach you're describing is "non-trivial". That means it might not be technically impossible, but so difficult to do correctly and has so many negatives/downsides that you will be better off stepping back and analyzing the larger problem for a different design. Perhaps if you re-posted articulating the end goal you're trying to accomplish, we can help you find an approach that is viable.

Rex M