Server Control Lifecycle Conflict
I'm working now on the UI controls framework of our company, and I've fallen into the following problem: I wanted to associate each input control to a text control, so that when the input control “visible” property is set to false, its title won't be visible either. For this to happen, I've defined a “TitleControl” property to each of the input controls, which contains the name of the title control associated with it. So far so good, and quite trivial. The problem began when I tried to figure out where exactly to put the code which hides the associated control.
My first choice was in the “Visible” property code itself (which I overrode). I found out this was not possible, since if the control is defined as not visible in the designer, the associated control may not even exist in the page when the Visible property is set.
The second one was on the “Load” control event. This solution presented another problem, since the framework (our framework, not the .NET framework) sets the visibility of the controls in the Load event of the page, which occurs AFTER the Load event of the controls.
The third, and so far last, try was to put it in the PreRender event of the control. This proved to be a bad idea, since if the control is not visible, the PreRender event (and its OnPrerender handler) does not even get called.
Scenarios like this make me sometimes wish I had another control event, something like “PageComplete” or “PostLoad“ which trigerred once the page, and not the control, is loaded. Until we'll have something like that (all the “Whidbey“ gurus out there - does it bring any change for this one?), there will be no event which will enable us to access the page after it was fully loaded, if the control is not visible.
The workaround I found for this specific scenarion is to add handler to the Page.Load event from the control, but this is not the most elegant solution that should be availabe.
Did you also had issues with the control's lifecycle? Did you find a better solution than mine? Pls let me know.