当前位置:编程学习 > 网站相关 >>

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:
[html] view plaincopy
[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 { }  
        }  
}  

 


补充:综合编程 , 其他综合 ,
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,