The DesignMode property of a nested user control is always set to False in Visual Studio .NET or in Visual Studio 2005

Symptoms

When you work with Microsoft Windows Forms in Microsoft Visual Studio .NET or in Microsoft Visual Studio 2005, the DesignMode property of a user control may be set to False.

Cause

This behavior occurs at design time in Microsoft Visual Studio .NET or in Microsoft Studio 2005 if you nest a user control inside another user control. When you do this, the DesignMode property of the nested user control will return False. If a user control contains another user control, only the root level user control will return True.

More Information

Steps to reproduce the behavior

  1. In Microsoft Visual Studio .NET or in Microsoft Visual Studio 2005, use Microsoft Visual Basic .NET or Microsoft Visual Basic 2005 to create a Windows Application project. By default, a Windows Form that is named Form1 is created.
  2. Add two new UserControl projects to the solution. Name the UserControl projects UserControl1 and UserControl2.
  3. In the UserControl1 project, open the UserControl1 control. Add a Label object to the control. Name the Label object label1.
  4. Add the following code to the Load event of the UserControl1 control.
    Me.label1.Text = this.DesignMode;
  5. Save and then build the project.
  6. Open the UserControl2 control, and then add the UserControl1 control to the UserControl2 control.
  7. Save and then build the project.
  8. In the Windows Forms project, open the Form1 form in design view, and then add the UserControl1 control and the UserControl2 control to the Form1 form.
The label of the nested UserControl1 control reads False, and the label of the non-nested UserControl1 control reads True.

Status

Microsoft has confirmed that this is a problem in the Microsoft products that are listed in the "Applies to" section.
Properties

Article ID: 839202 - Last Review: May 13, 2008 - Revision: 1

Feedback