How to add custom property in custom webpart using VS 2012

How to add custom property in custom webpart using VS 2012

Sometimes we want to add some custom properties to custom web part, then we can edit the value of the custom properties. here is the picture

And the StorePortal is my custom properties, and I also set the default value of the custom properties.

Firstly, yopu should create a empty sharepoint project and add new item call webpart to the project.

Second, if you want to add cutom properties, just use the follow code:

        [WebBrowsable(true),  
            WebDisplayName("This is Name"),                             // The display name  
            WebDescription("This is Description, e.g. 'blog1#blog2'"),  // the description of the custom properties
            Personalizable(PersonalizationScope.Shared),  
            Category("This is new category")]                           // to display the properties in a new section  
        public string BlogWeb { get; set; }  

 

the code is following:

    [ToolboxItemAttribute(false)]
    public class render : WebPart
    {

        #region Custom web part properties

        // blog web related url, e.g. "/blog"        
        [WebBrowsable(true),
            WebDisplayName("Blog web related url"),
            WebDescription("Blog web related url, e.g. 'blog1#blog2'"),
            Personalizable(PersonalizationScope.Shared),
            Category("StorePortal")]
        public string BlogWeb { get; set; }

        // the number of show tags, e.g. 10    
        [WebBrowsable(true),
            WebDisplayName("The number of tags"),
            WebDescription("The number of tags, e.g. 1"),
            Personalizable(PersonalizationScope.Shared),
            Category("StorePortal"),
            DefaultValue(NumberLimitDefaultValue)]
        public uint NumberLimit { get { return this.numberLimit; } set { this.numberLimit = value; } }

        #endregion

        #region private fields

        private const uint NumberLimitDefaultValue = 10;
        private uint numberLimit = NumberLimitDefaultValue;

        #endregion

        protected override void CreateChildControls()
        {
            //try
            //{
            // you can cutom to coding, and if you want to call the custom properties. For example: this.BlogWeb
            //}
            //catch { }
        }
}


 

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值