This post briefly covers how to create custom web part settings in your Visual Studio solution.
In the main webPart.CS file add the following settings:
// Custom WP Setting – English RSS URL
[Personalizable(PersonalizationScope.Shared),
WebBrowsable(true),
WebDisplayName(“English RSS URL”),
WebDescription(“Enter the English RSS URL”),
Category(“Custom Web Part Settings”)]
publicstring ENRSSUrl { get; set; }
// Custom WP Setting – English RSS URL
[Personalizable(PersonalizationScope.Shared),
WebBrowsable(true),
WebDisplayName(“French RSS URL”),
WebDescription(“Enter the French RSS URL”),
Category(“Custom Web Part Settings”)]
publicstring FRRSSUrl { get; set; }
Update the createChildControls method:
protected override void CreateChildControls()
{
Control control = Page.LoadControl(_ascxPath);
// Reference public properties in visual webpart control
VisualWebPart1UserControl vswebcontrol = control asVisualWebPart1UserControl;
// Pass through the values to the web part control
vswebcontrol.toolPartENRSSUrl = ENRSSUrl;
vswebcontrol.toolPartFRRSSUrl = FRRSSUrl;
Controls.Add(control);
}
Reference the settings in the main web part control class:
public partialclass VisualWebPart1UserControl : UserControl
{
// Public Properties
public string toolPartENRSSUrl { get; set; }
public string toolPartFRRSSUrl { get;set; }
// Internal strings
string ENURL = string.Empty;
string FRURL = string.Empty;
protectedvoid Page_Load(object sender, EventArgs e)
{
// Set the string values
ENURL = toolPartENRSSUrl;
FRURL = toolPartFRRSSUrl;
// Reference the custom web part settings
lblEN.Text = ENURL;
LblFR.Text = FRURL;
}
}
It’s as simple as this !