Creating Custom Web Part Properties


/ Published in: C#
Save to your folder(s)

Steps to add custom properties to web part


Copy this code and paste it in your HTML
  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. }

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

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.