Thursday, January 26, 2017

How to create a SharePoint webpart with custom webpart property/properties


Recently one of colleague want to create a webpart for SharePoint using C# as programming language. One of his requirements is to that “user wants to pass values through custom webpart property.” So I created a sample for him.


Here is the code and also you can download the .sln file from my drive by clicking below URL.

namespace CustomProperty.CustomWebPartProperty
    public class CustomWebPartProperty : WebPart
        private string _name = "Suhail";//The default value to display
        WebDisplayName("Label Text"),//WebPart property display name
        WebDescription("Label Text to appear in Label"),//Property discription
        Category("Custom"),//Custom webpart property catogory
        public string Name
                return _name;
                _name = value;

        protected override void CreateChildControls()
            Label name = new Label();
            name.Text = Name;



You can see your custom webpart property at the end of the webpart setting.

When you need values which should be able customize don’t save in web.config file; You may use custom webpart properties.

No comments:

Post a Comment