I have a requirement for building a budget report which has the same key fields for 6 different categories. I have written a visual web part which pulls a listitem for each section and displays the data along with an edit button. There is also a custom property in the webpart to store the type of budget:
public class ProjectDetailsView : WebPart
{
// Visual Studio might automatically update this path when you change the Visual Web Part project item.
private const string _ascxPath = @"~/_CONTROLTEMPLATES/SpecialProjectsProjectList/ProjectDetailsView/ProjectDetailsViewUserControl.ascx";
[Personalizable(), WebBrowsable]
public String BudgetType { get; set; }
protected override void CreateChildControls()
{
ProjectDetailsViewUserControl control = Page.LoadControl(_ascxPath) as ProjectDetailsViewUserControl;
//Control control = Page.LoadControl(_ascxPath);
if (control != null)
{
control.WebPart = this;
}
Controls.Add(control);
}
}
}
I have added this visual wepart 6 times on the same page. It seems that only the first control is actually saving the custom property. Is this likely an error in the code, or can you not have the same webpart numerous times on the same page?
I don't want to spend hours debugging if someone already knows I need to create a separate control per section. Many thanks!