0

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

4

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; }
  ...
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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