Share via


How to: Create a User Control for a SharePoint Application Page or Web Part

You can create a custom control and include it in a Web Part or Application Page. A user control is a composite control to which you can add other ASP.NET controls and SharePoint controls. You can also define properties and methods for the control. For more information, see Creating Reusable Controls for Web Parts or Application Pages.

To create a user control for SharePoint

  1. Open or create a SharePoint project in Visual Studio. For more information, see SharePoint Project and Project Item Templates.

  2. In Solution Explorer, select the project node.

  3. On the Project menu, click Add New Item.

  4. In the Add New Item dialog box, in the Installed Templates pane, expand the SharePoint node, and then click 2010.

  5. In the list of SharePoint templates, select User Control.

  6. Type a name for the user control in the Name box, and then click Add.

    Visual Studio adds a number of folders and files to your project. For more information about these files, see Creating Reusable Controls for Web Parts or Application Pages.

    By default, the user control file appears in the Source view of the Visual Web Developer designer. Source view enables you to edit the XML markup of the control.

  7. Switch to Design view if you want to design the control visually by dragging controls from the Toolbox. For more information, see Design View, Web Page Designer.

  8. To handle control events, add code to the code file of the user control.

    This file appears in Solution Explorer below the user control file. The code file has a .cs or .vb extension depending on the language of the project.

See Also

Other Resources

Creating Reusable Controls for Web Parts or Application Pages

Creating Application Pages for SharePoint

Creating Web Parts for SharePoint