|Important||This document may not represent best practices for current development, links to downloads and other resources may no longer be valid. Current recommended version can be found here.|
How to: Create ASP.NET User Controls (Visual Studio)
You create ASP.NET user controls in much the same way that you design ASP.NET Web pages. You can use the same HTML elements and controls on a user control that you do on a standard ASP.NET page. However, the user control does not have html, body, and form elements; and the file name extension must be .ascx.
To create an ASP.NET user control
Open the Web site project to which you want to add user controls. If you do not already have a Web site project, you can create one. For more information, seeor .
On the Website menu, click Add New Item.
The Add New Item dialog box appears.
In the Add New Item dialog box, under Visual Studio installed templates, click Web User Control.
In the Name box, type a name for the control.
By default, the .ascx file name extension is appended to the control name that you type.
From the Language list, select the programming language that you want to use.
Optionally, if you want to keep any code for the user control in a separate file, select the Place code in separate file check box.
The new ASP.NET user control is created and then opened in the designer. The markup for this new control is similar to the markup for an ASP.NET Web page, except that it contains andirective instead of an directive, and the user control does not have html, body, and form elements.
Add any markup and controls to the new user control, and add code for any tasks that the user control will perform, such as handling control events or reading data from a data source.
For the complete syntax of an example ASP.NET user control, see.