Notice: This website is an unofficial Microsoft Knowledge Base (hereinafter KB) archive and is intended to provide a reliable access to deleted content from Microsoft KB. All KB articles are owned by Microsoft Corporation. Read full disclaimer for more details.

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

View products that this article applies to.

This article was previously published under Q316370

↑ Back to the top


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.

↑ Back to the top


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

↑ Back to the top


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

↑ Back to the top

More information

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.

↑ Back to the top

Keywords: kbvs2002sp1sweep, kbbug, kbctrlcreate, kbide, kbpending, KB316370

↑ Back to the top

Article Info
Article ID : 316370
Revision : 10
Created on : 2/23/2007
Published on : 2/23/2007
Exists online : False
Views : 519