Memi.Reflection

Private members of memi's thoughts

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.

Posted: Feb 28 2004, 09:30 PM by memi | with 3 comment(s)
Filed under:

Comments

Yuri Gorobets said:

Hi Memi,
IMO, you could add the new property , something like IsVisible on the Server Side.
The your customized Visible property always set to true;
Now, in OnPrerender, for instance you'll add the Style "display" attribute according to you IsVisible property: block or none.
I think it will give you complete and independent solution to your problem.
# February 29, 2004 3:18 AM

Memi Lavi said:

Hi.
I thought of this solution, but I don't want to have two "visible" properties on the control. It will lead, somewhere in the future, to confusion and inconsistency. In addition, there will still be a problem if the control "original" visibiliy is set to false by other methods. In this case, the title control will still be visible.
# February 29, 2004 4:53 AM

Guy Sofer said:

I would move visibility dependencies between elements to be handled by client side JS event handlers. But with this approach the assumption is the the entry form is already gets to the client (I don't sure this is what you want). I do have a similar problem on a project I'm involved right now. You can see more details on this approach within my blog
http://weblogs.asp.net/guys/articles/93521.aspx
# April 8, 2004 12:59 PM
Leave a Comment

(required) 

(required) 

(optional)

(required)