views:

76

answers:

3

Curiosity is kicking out again. I've been using the user control .Visible and .Hide() method for a long time. So where does a user-control go when the visibility of it is set to false?

+3  A: 

It doesn't go anywhere - it stays in memory. It's just that its not visible. Being visible really means that it has to paint its area when requested and it can receive focus and user actions.

VinayC
Is it the same as saving the user controls property to the memory?
Rye
Not really - user control will have lot other state information apart from its properties - for example, there will be window associated with it. Besides there are other controls within the user control, whose state information will also be there in the memory.
VinayC
Thanks for explaining @VinayC.
Rye
+1  A: 

When you set the Visible property on a control it essentially tells the web server not to return the HTML markup for the control in the response. It does, however, keep the control's information in the viewstate so you can keep working with it in your code.

Oops - sorry. I thought you were talking about ASP.NET and not WinForms. My bad.

Steopa
he's speaking about winforms. If it was about ASP.NET, your answer would be great...
chiccodoro
So that's how it works on ASP. Good stuff.
Rye
A: 

I'd agree with VinayC (+1 btw).

Also, even though the control doesn't paint itself or respond to user events through the UI you can still exercise it programmatically or indeed use its data.

For example you could have an invisible window that logs posted message data.

You actually use this functionality quite a lot without thinking about it, take your Form control for example. For a modal dialog box you create it, set property values whilst it is hidden then make it visible with the ShowDialog() method.

ChrisBD