Add properties to visual webparts sharepoint 2010
This post talks on how one can add custom properties to their SharePoint 2010 visual webparts. Microsoft has brought visual webparts for easing the developer life with SharePoint 2010 development. But when it comes to adding some custom properties for these webparts then there is bit of trouble hidden.
To troubleshoot this issue lets us dive in entities inside webpart project.
- Inside the webparts folder of the project one can see following files (considering webpart name as “VisualWebPart1”):
- Webpart class “VisualWebPart1.cs” that is derived from webpart class
- User control file “VisualWebPart1UserControl.ascx” and its associated designer and .cs files
Since we think that merely writing the property and setting its attributes to WebBrowsable=true & Personalizable inside the usercontrol class (VisualWebPart1UserControl.ascx.cs) file will go ahead and add properties into webpart, but in reality this will not work.
So how we gonna do this?
Even though the above assumption of ours is true but its partially true. The fact is, before adding this property to user control class we should