Create Visual Webpart with Custom Properties in SharePoint 2013

Now, Lets see how to create custom web parts to a visual web part in SharePoint 2013.

If you used new Visual Web Part Template in Visual Studio 2012 to Create Custom WebParts you have first learn about the basic structure of the Visual Web Part in SharePoint 2013.Creating custom properties in SharePoint 2013 is different from creating a Visual Web Part with custom properties in SharePoint 2010. In SharePoint 2013, there is no separate User Control Class( webpartname.cs ) and only web part class (webpartname.aspx.cs) is available. we can directly write custom properties in User Control Class.

following is the SharePoint 2013 Visual Web Part architecture

SharePoint 2013 Custom Properties

Now, follow below steps to create a Visual Webpart with Custom Properties in SharePoint 2013. I will show how to create a drop down menu in this article. similarly, you can also create textbox, boolean value,check box etc.
Refer MSDN for Different Custom Properties.

Add Custom Properties to a Visual Web Part:

  • Add a Visual Web Part to your project.
  • Create a new property by adding the below code in your user control class(webpartname.aspx.cs).

public enum CustomProp

 Category("Custom Configurations"),
 WebDisplayName("WebPart Properties"),
 WebDescription("Select a properties to change the WebPart display")]

 public CustomProp WebPartProperty { get; set; }

Using this property in Code behind:

 protected void Page_Load(object sender, EventArgs e)
  if (!Page.IsPostBack)
     lblProjects.Text = this.WebPartProperty.ToString();

Build and deploy the solution.
  • Add the Web Part to a Page and Edit the Web Part to see properties.

SharePoint 2013 Custom Properties
  • Click OK, You can see your Custom Properties displayed on your page.
Hope this is helpful for you.

Sudheer Gangumolu

I'm a Software Analyst / Developer / Blogger, having good experience in working with different flavors & Customization of SharePoint (i.e.,SP O365 / 2013 / 2010 / 2007) and .Net Apps. Currently, working on SharePoint 2013 / SharePoint O365. Guiding people on my technologies.

    Blogger Comment
    Facebook Comment


  1. It would be great if you provide JavaScript solution for the same as it's trend of sandbox solution after release of SharePoint2013

  2. Thanks for taking time to check my site, we are trying to provide you the same in the coming days.