0

我正在寻找将自定义属性添加到工具部件。我已经能够根据需要添加文本框。我已经能够输入值并将其显示在 Web 部件中。

问题是当我编辑 web 部件时 - 面板弹出,但我添加的控件未填充先前输入的值。见下文:

为什么这不起作用? :(

我完全按照本网站上的说明进行了操作——我自己和更有经验的 Sharepoint 开发人员同事都无法弄清楚这里发生了什么。

我们认为重写 SyncChanges() 方法将允许这样做 - 似乎没有,除非我们的实现不正确?

    public override void SyncChanges()
    {
        DemoWebPart wp = (DemoWebPart)this.ParentToolPane.SelectedWebPart;
        urls.Text = wp.ListValue;
    }

我们还为 DemoWebPart.cs 类的 urls 属性添加了以下前缀,但无济于事:

    [Browsable(true), Category("Miscellaneous"),
    DefaultValue("Site Names"),
    WebPartStorage(Storage.Shared / Personal / None),
    FriendlyName("URLs"), Description("Text Property")]

(已尝试 Storage.Shared、Storage.Personal 和 Storage.None)。

您可以提供的任何帮助将不胜感激 - 在此先感谢!

4

3 回答 3

1

如果 Webpart 个性化在中央管理中启用,则仅使用以下内容:

Personalizable(PersonalizationScope.Shared)

如果不是,请完全删除 Personalizable 属性。不要在其中输入 false 或 none,删除该属性并使用它:

WebPartStorage(Storage.Shared)
于 2012-10-26T17:34:21.953 回答
1

这是我通常用于此类属性的代码:

[Personalizable(PersonalizationScope.Shared)]
[WebBrowsable(true)]
[System.ComponentModel.Category("Custom")]
[WebDisplayName("DisplayNameGoesHere")]
[WebDescription("Type the description of this web property here.")]
public string MyProperty{ get; set; }

我从来没有遇到过任何问题。

于 2012-01-24T15:39:28.357 回答
0

建议 :

  1. 创建一个新的 WP
  2. 并使用这篇文章http://snahta.blogspot.com/2009/11/webpart-custom-properties.html

我已经使用了 100 次,请尝试一下,它会起作用的。

谢谢桑迪普

于 2012-01-25T05:25:17.210 回答