Microsoft KB Archive/316370

= BUG: Visual Studio .NET does not generate a code-behind declaration for Web User controls =

Article ID: 316370

Article Last Modified on 2/23/2007

-

APPLIES TO


 * Microsoft Visual Studio .NET 2003 Professional Edition
 * Microsoft Visual Studio .NET 2002 Professional Edition
 * Microsoft Visual Studio .NET 2003 Enterprise Architect
 * Microsoft Visual Studio .NET 2002 Enterprise Architect
 * Microsoft Visual Studio .NET 2003 Enterprise Developer
 * Microsoft Visual Studio .NET 2002 Enterprise Developer
 * Microsoft Visual Studio .NET 2003 Academic Edition
 * Microsoft Visual Studio .NET 2002 Academic Edition
 * Microsoft ASP.NET 1.1
 * Microsoft ASP.NET 1.0

-



This article was previously published under Q316370



SYMPTOMS
When you create a Web User control and drag it to an .aspx page, Visual Studio .NET does not automatically generate a code-behind declaration for the Web User control.



RESOLUTION
To resolve this problem, manually enter the declaration for the Web User control in the code-behind file. The following two code examples show a Web Form (WebForm1) with an embedded Button control. You can add the declaration for the Web User control in the same place that Visual Studio .NET adds the declaration for the Button control.

Microsoft Visual C# .NET example
public class WebForm1 : System.Web.UI.Page {   protected System.Web.UI.WebControls.Button Button1; protected WebUserControl1 ctlMyControl;

Microsoft Visual Basic .NET example
Public Class WebForm1 Inherits System.Web.UI.Page Protected WithEvents Button1 As System.Web.UI.WebControls.Button Protected WithEvents ctlMyControl As WebUserControl1



STATUS
Microsoft has confirmed that this is a bug in the Microsoft products that are listed in the &quot;Applies to&quot; section.



Steps to reproduce the problem

 * 1) Start Visual Studio .NET, and then create a new Web Application project in Visual C# .NET.
 * 2) In Visual Studio .NET, on the Project menu, click Add Web User Control, and then click Open in the resultant dialog box.
 * 3) In Solution Explorer, double-click the default Web Form.
 * 4) Add a Button control to the Designer.
 * 5) Add your Web User control to the Designer.
 * 6) View the code-behind class for your Web Form.

Note There is a declaration for the Button control, but not for the Web User control in the class declaration.

Keywords: kbvs2002sp1sweep kbbug kbctrlcreate kbide kbpending KB316370

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.