Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

Soo,

I created an webpart, and I've added a custom property. The webpart works fine.

Now I want to add this webpart in another page also, but with a different property value. The problem is that if I set the property value it will update all the values in all the webparts of this type in my site.

What should I do?

Here is my code:

[ToolboxItemAttribute(false)]
public class ListWebPart : WebPart
{
    public static string List;
    [Category("Extended Settings"),
    Personalizable(PersonalizationScope.Shared),
    WebBrowsable(true),
    WebDisplayName("List"),
    WebDescription("Please Enter a Sample List"),
    DefaultValue("Posts")]

    ect

PS: Shorty scenario If you add a web part in page 1 and set the title: Webpartbla than you add the same web part in another page and set the title: webpartbla1 it will remember this values of the same webpart in different pages. This won't work with custom properties, like the one above

share|improve this question
add comment

1 Answer

up vote 4 down vote accepted

Don't make property List static

EDIT:

Working code:

[ToolboxItemAttribute(false)]
public class MyDetailWebPart : WebPart {
  ...
  [Personalizable(PersonalizationScope.Shared)]
  [WebBrowsable(true)]
  [Category("Category")]
  [WebDisplayName("Name")]
  [Description("Desc")]
  public string Code { get; set; }
  ...
  protected override void CreateChildControls()
    {
        var control = (MyControl)Page.LoadControl(_ascxPath);
        control.Code = Code;
        Controls.Add(control);
    }
}

public partial class MyControl : UserControl
{
  ...
  public string Code { get; set; }
  ...
}
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.