DesignTime question

T

Tamir Khason

I have a user control (control_1) wich holds other user control (control_2)
In control_1 there is:
if(!DesignMode) {cont = new control_2; }so in design mode I can not see the
user control_2 inside, this works fine untill I add control_1 to form or
other control. In this case the constrain !DesignMode returns true
(control_1 thinks that this is run time). How to make condition (without
messing with each one of forms, holds control_1) not to initialize control_2
while degin mode

TNX
 
S

Sijin Joseph

The DesignMode property is not declared virtual, give this code a shot

if(! this.Site.DesignMode ) { cont = new control_2; }

Also from the MSDN docs
"The design mode indicator is stored in the ISite; therefore, if the
Component does not have an ISite associated with it, this property is
always false."



Sijin Joseph
http://www.indiangeek.net
http://weblogs.asp.net/sjoseph
 
T

Tamir Khason

Small problem there
this.Site.DesignMode // No reference 'cos this.Site = null !!! why?
 
J

Jeffrey Tan[MSFT]

Hi Tamir,

Thanks for your posting.

Where do you place this code snippet? I think you may place it in
Usercontrol1's constructor or InitializeComponent(). In these 2 places, the
site(which is the communication between the control and its container) is
not initialized, so it will be null reference.

You should detect the operation in Load event, where the Site property has
been initialized well. Like this:
private UserControl uc=null;
private void UserControl1_Load(object sender, System.EventArgs e)
{
if(!this.Site.DesignMode)
{
uc=new UserControl();
this.Controls.Add(uc);
}
}

==========================================
Please apply my suggestion above and let me know if it helps resolve your
problem.

Thank you for your patience and cooperation. If you have any questions or
concerns, please feel free to post it in the group. I am standing by to be
of assistance.

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
 
J

Jeffrey Tan[MSFT]

Hi Tamir,

Does my reply make sense to you? Do you still have concern on this issue?

Please feel free to feedback. Thanks

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top