Container Control Open Event

I have a control control containing a label to display username. This container control is used in multiple windows. In the open event of container control i retrieve username from database and assigning to the label(username will be retrieved based on the logged in user). The open event fires before the login process(while running the application itself the open event fires). So always username will be NULL.

its possible to assign value to the label by specifying each window name as

window1.ccName1.label1.text=“name”
window2.ccName1.label1.text=“name”
window3.ccName1.label1.text=“name”

Is there any way to simplify this by single line code in open event of ccName container control itself. The open event should fire after login process apart from initial loading.

Please help

Thanks
Hema

The ContainerControl should never refer to a specific instance, so your design is already not what it should be.

If your controls depend on the database then you need to open the database first. So start with a login window that opens the database, and only proceed and open other windows when you have a successful connection.

This is a classic use of the observer design pattern.

hi Markus Winter,

Yes it works if the windows as different. If we use page panel inside a single window and adding each container control as a pages of page panel. Then whats the solution. Because by loading the window itself all are initialized.

Sorry in the previous post one mistake was there, same window with different container control as

window1.ccMainHome1.ccName1.label1.text=“name”
window1.ccUserHome1.ccName1.label1.text=“name”
window1.ccFeedback1.ccName1.label1.text=“name”

[quote=247714:@Hemalatha GK]hi Markus Winter,

Yes it works if the windows as different. If we use page panel inside a single window and adding each container control as a pages of page panel. Then whats the solution. Because by loading the window itself all are initialized.

Sorry in the previous post one mistake was there, same window with different container control as

window1.ccMainHome1.ccName1.label1.text=“name”
window1.ccUserHome1.ccName1.label1.text=“name”
window1.ccFeedback1.ccName1.label1.text=“name”[/quote]

Referring to a containers innards directly is still a bad idea
You containers should hide all their innards (make all the controls private)
THen expose public methods or compute properties that you set on the container and then in the containers implementation of those methods / computed properties that code then sets the label etc
That way users of the control do not have to know about the innards in order to use them