Muokkaa

Jaa


Create a user control for a SharePoint application page or web part

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

  1. In Visual Studio, open or create a SharePoint project.

    See SharePoint project and project item templates.

  2. In Solution Explorer, choose the project node.

  3. On the menu bar, choose Project > Add New Item.

    The Add New Item dialog box opens.

  4. In the Installed pane, choose the Office/SharePoint node.

  5. In the list of SharePoint templates, choose User Control (Farm Solution Only).

    Note

    User controls work only in farm solutions.

  6. 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.

  7. 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.