How to: Create a user control for a SharePoint application page or web part
Applies to: Visual Studio Visual Studio for Mac Visual Studio Code
You can create custom user controls that provide custom functionality for your SharePoint solution, and you can reuse that functionality within your project. You can include the user controls in a web part or application page, add other ASP.NET controls and SharePoint controls, and define properties and methods for the control. For more information about user controls, see Create reusable controls for web parts or application pages and User Controls and Server Controls in SharePoint.
To create a user control for SharePoint
In Visual Studio, open or create a SharePoint project.
In Solution Explorer, choose the project node.
On the menu bar, choose Project > Add New Item.
The Add New Item dialog box opens.
In the Installed pane, choose the Office/SharePoint node.
In the list of SharePoint templates, choose User Control (Farm Solution Only).
User controls work only in farm solutions.
In the Name box, specify a name for the user control, and then choose the Add button.
Visual Studio adds several folders and files to your project. For more information about these files, see Create 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. In this view, you can edit the XML markup of the control. You can switch to Design view if you want to design the control visually by dragging controls from the Toolbox. See Design View, Web Page Designer.
If you want to handle events that occur in the control, add code to the code file of the user control.
This file appears in Solution Explorer under the user control file and has a .cs or .vb extension, depending on the language of the project.