Posted By

nickaranz on 04/26/11


Tagged

Development sharepoint 2010


Versions (?)

Creating Custom Web Part Properties


 / Published in: C#
 

URL: http://blog.concurrency.com/sharepoint/create-a-custom-web-part-for-sharepoint-2010/

Steps to add custom properties to web part

  1. // MyWebPart.cs
  2. [WebBrowsable(true),
  3. Category("Miscellaneous"),
  4. Personalizable(PersonalizationScope.Shared),
  5. WebDisplayName("Enter some text")]
  6. public string CustomTextProp { get; set; }//textbox
  7. // options: public bool CustomCheckboxProp { get; set; }
  8. // public ddlEnum ddlProp { get; set; } //this is required: public enum ddlEnum { option1, option2, option3 }//dropdown
  9.  
  10. //MyWebPartUserControl.ascx.cs
  11. public MyWebPart WebPart { get; set; }
  12.  
  13. //MyWebPart.cs
  14. protected override void CreateChildControls()
  15. {
  16. MyWebPartUserControl control = Page.LoadControl(_ascxPath) as MyWebPartUserControl;
  17. if (control != null)
  18. control.WebPart = this;
  19. Controls.Add(control);
  20. }
  21. }

Report this snippet  

You need to login to post a comment.